Blame view

drivers/char/toshiba.c 13.3 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  /* toshiba.c -- Linux driver for accessing the SMM on Toshiba laptops
   *
   * Copyright (c) 1996-2001  Jonathan A. Buzzard (jonathan@buzzard.org.uk)
   *
   * Valuable assistance and patches from:
   *     Tom May <tom@you-bastards.com>
   *     Rob Napier <rnapier@employees.org>
   *
   * Fn status port numbers for machine ID's courtesy of
   *     0xfc02: Scott Eisert <scott.e@sky-eye.com>
   *     0xfc04: Steve VanDevender <stevev@efn.org>
   *     0xfc08: Garth Berry <garth@itsbruce.net>
   *     0xfc0a: Egbert Eich <eich@xfree86.org>
   *     0xfc10: Andrew Lofthouse <Andrew.Lofthouse@robins.af.mil>
   *     0xfc11: Spencer Olson <solson@novell.com>
   *     0xfc13: Claudius Frankewitz <kryp@gmx.de>
   *     0xfc15: Tom May <tom@you-bastards.com>
   *     0xfc17: Dave Konrad <konrad@xenia.it>
   *     0xfc1a: George Betzos <betzos@engr.colostate.edu>
   *     0xfc1b: Munemasa Wada <munemasa@jnovel.co.jp>
   *     0xfc1d: Arthur Liu <armie@slap.mine.nu>
   *     0xfc5a: Jacques L'helgoualc'h <lhh@free.fr>
   *     0xfcd1: Mr. Dave Konrad <konrad@xenia.it>
   *
   * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
   *
   *   This code is covered by the GNU GPL and you are free to make any
   *   changes you wish to it under the terms of the license. However the
   *   code has the potential to render your computer and/or someone else's
   *   unusable. Please proceed with care when modifying the code.
   *
   * Note: Unfortunately the laptop hardware can close the System Configuration
   *       Interface on it's own accord. It is therefore necessary for *all*
   *       programs using this driver to be aware that *any* SCI call can fail at
   *       *any* time. It is up to any program to be aware of this eventuality
   *       and take appropriate steps.
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License as published by the
   * Free Software Foundation; either version 2, or (at your option) any
   * later version.
   *
   * This program is distributed in the hope that it will be useful, but
   * WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * General Public License for more details.
   *
   * The information used to write this driver has been obtained by reverse
   * engineering the software supplied by Toshiba for their portable computers in
   * strict accordance with the European Council Directive 92/250/EEC on the legal
   * protection of computer programs, and it's implementation into English Law by
   * the Copyright (Computer Programs) Regulations 1992 (S.I. 1992 No.3233).
   *
   */
  
  #define TOSH_VERSION "1.11 26/9/2001"
  #define TOSH_DEBUG 0
  
  #include <linux/module.h>
  #include <linux/kernel.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
62
63
64
65
66
67
68
69
  #include <linux/types.h>
  #include <linux/fcntl.h>
  #include <linux/miscdevice.h>
  #include <linux/ioport.h>
  #include <asm/io.h>
  #include <asm/uaccess.h>
  #include <linux/init.h>
  #include <linux/stat.h>
  #include <linux/proc_fs.h>
967bb77c6   Alexey Dobriyan   [PATCH] seq_file ...
70
  #include <linux/seq_file.h>
613655fa3   Arnd Bergmann   drivers: autoconv...
71
  #include <linux/mutex.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
73
74
  #include <linux/toshiba.h>
  
  #define TOSH_MINOR_DEV 181
3f5f7e2ee   Dmitry Torokhov   [PATCH] Toshiba d...
75
76
77
78
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("Jonathan Buzzard <jonathan@buzzard.org.uk>");
  MODULE_DESCRIPTION("Toshiba laptop SMM driver");
  MODULE_SUPPORTED_DEVICE("toshiba");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79

613655fa3   Arnd Bergmann   drivers: autoconv...
80
  static DEFINE_MUTEX(tosh_mutex);
3f5f7e2ee   Dmitry Torokhov   [PATCH] Toshiba d...
81
82
83
  static int tosh_fn;
  module_param_named(fn, tosh_fn, int, 0);
  MODULE_PARM_DESC(fn, "User specified Fn key detection port");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84

3f5f7e2ee   Dmitry Torokhov   [PATCH] Toshiba d...
85
86
87
88
89
  static int tosh_id;
  static int tosh_bios;
  static int tosh_date;
  static int tosh_sci;
  static int tosh_fan;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90

3e8d95d95   Alan Cox   tosh: Use non bkl...
91
  static long tosh_ioctl(struct file *, unsigned int,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
  	unsigned long);
62322d255   Arjan van de Ven   [PATCH] make more...
93
  static const struct file_operations tosh_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
  	.owner		= THIS_MODULE,
3e8d95d95   Alan Cox   tosh: Use non bkl...
95
  	.unlocked_ioctl	= tosh_ioctl,
6038f373a   Arnd Bergmann   llseek: automatic...
96
  	.llseek		= noop_llseek,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
  };
  
  static struct miscdevice tosh_device = {
  	TOSH_MINOR_DEV,
  	"toshiba",
  	&tosh_fops
  };
  
  /*
   * Read the Fn key status
   */
  #ifdef CONFIG_PROC_FS
  static int tosh_fn_status(void)
  {
          unsigned char scan;
  	unsigned long flags;
  
  	if (tosh_fn!=0) {
  		scan = inb(tosh_fn);
  	} else {
  		local_irq_save(flags);
  		outb(0x8e, 0xe4);
  		scan = inb(0xe5);
  		local_irq_restore(flags);
  	}
  
          return (int) scan;
  }
  #endif
  
  
  /*
   * For the Portage 610CT and the Tecra 700CS/700CDT emulate the HCI fan function
   */
  static int tosh_emulate_fan(SMMRegisters *regs)
  {
  	unsigned long eax,ecx,flags;
  	unsigned char al;
  
  	eax = regs->eax & 0xff00;
  	ecx = regs->ecx & 0xffff;
  
  	/* Portage 610CT */
  
  	if (tosh_id==0xfccb) {
  		if (eax==0xfe00) {
  			/* fan status */
  			local_irq_save(flags);
  			outb(0xbe, 0xe4);
  			al = inb(0xe5);
  			local_irq_restore(flags);
  			regs->eax = 0x00;
  			regs->ecx = (unsigned int) (al & 0x01);
  		}
  		if ((eax==0xff00) && (ecx==0x0000)) {
  			/* fan off */
  			local_irq_save(flags);
  			outb(0xbe, 0xe4);
  			al = inb(0xe5);
  			outb(0xbe, 0xe4);
  			outb (al | 0x01, 0xe5);
  			local_irq_restore(flags);
  			regs->eax = 0x00;
  			regs->ecx = 0x00;
  		}
  		if ((eax==0xff00) && (ecx==0x0001)) {
  			/* fan on */
  			local_irq_save(flags);
  			outb(0xbe, 0xe4);
  			al = inb(0xe5);
  			outb(0xbe, 0xe4);
  			outb(al & 0xfe, 0xe5);
  			local_irq_restore(flags);
  			regs->eax = 0x00;
  			regs->ecx = 0x01;
  		}
  	}
  
  	/* Tecra 700CS/CDT */
  
  	if (tosh_id==0xfccc) {
  		if (eax==0xfe00) {
  			/* fan status */
  			local_irq_save(flags);
  			outb(0xe0, 0xe4);
  			al = inb(0xe5);
  			local_irq_restore(flags);
  			regs->eax = 0x00;
  			regs->ecx = al & 0x01;
  		}
  		if ((eax==0xff00) && (ecx==0x0000)) {
  			/* fan off */
  			local_irq_save(flags);
  			outb(0xe0, 0xe4);
  			al = inb(0xe5);
  			outw(0xe0 | ((al & 0xfe) << 8), 0xe4);
  			local_irq_restore(flags);
  			regs->eax = 0x00;
  			regs->ecx = 0x00;
  		}
  		if ((eax==0xff00) && (ecx==0x0001)) {
  			/* fan on */
  			local_irq_save(flags);
  			outb(0xe0, 0xe4);
  			al = inb(0xe5);
  			outw(0xe0 | ((al | 0x01) << 8), 0xe4);
  			local_irq_restore(flags);
  			regs->eax = 0x00;
  			regs->ecx = 0x01;
  		}
  	}
  
  	return 0;
  }
  
  
  /*
   * Put the laptop into System Management Mode
   */
  int tosh_smm(SMMRegisters *regs)
  {
  	int eax;
  
  	asm ("# load the values into the registers
  \t" \
  		"pushl %%eax
  \t" \
  		"movl 0(%%eax),%%edx
  \t" \
  		"push %%edx
  \t" \
  		"movl 4(%%eax),%%ebx
  \t" \
  		"movl 8(%%eax),%%ecx
  \t" \
  		"movl 12(%%eax),%%edx
  \t" \
  		"movl 16(%%eax),%%esi
  \t" \
  		"movl 20(%%eax),%%edi
  \t" \
  		"popl %%eax
  \t" \
  		"# call the System Management mode
  \t" \
  		"inb $0xb2,%%al
  \t"
  		"# fill out the memory with the values in the registers
  \t" \
  		"xchgl %%eax,(%%esp)
  \t"
  		"movl %%ebx,4(%%eax)
  \t" \
  		"movl %%ecx,8(%%eax)
  \t" \
  		"movl %%edx,12(%%eax)
  \t" \
  		"movl %%esi,16(%%eax)
  \t" \
  		"movl %%edi,20(%%eax)
  \t" \
  		"popl %%edx
  \t" \
  		"movl %%edx,0(%%eax)
  \t" \
  		"# setup the return value to the carry flag
  \t" \
  		"lahf
  \t" \
  		"shrl $8,%%eax
  \t" \
  		"andl $1,%%eax
  " \
  		: "=a" (eax)
  		: "a" (regs)
  		: "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
  
  	return eax;
  }
0bf932260   Randy Dunlap   [PATCH] export to...
276
  EXPORT_SYMBOL(tosh_smm);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
277

3e8d95d95   Alan Cox   tosh: Use non bkl...
278
  static long tosh_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
  {
  	SMMRegisters regs;
  	SMMRegisters __user *argp = (SMMRegisters __user *)arg;
  	unsigned short ax,bx;
  	int err;
  
  	if (!argp)
  		return -EINVAL;
  
  	if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
  		return -EFAULT;
  
  	switch (cmd) {
  		case TOSH_SMM:
  			ax = regs.eax & 0xff00;
  			bx = regs.ebx & 0xffff;
  			/* block HCI calls to read/write memory & PCI devices */
  			if (((ax==0xff00) || (ax==0xfe00)) && (bx>0x0069))
  				return -EINVAL;
  
  			/* do we need to emulate the fan ? */
613655fa3   Arnd Bergmann   drivers: autoconv...
300
  			mutex_lock(&tosh_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
301
302
303
  			if (tosh_fan==1) {
  				if (((ax==0xf300) || (ax==0xf400)) && (bx==0x0004)) {
  					err = tosh_emulate_fan(&regs);
613655fa3   Arnd Bergmann   drivers: autoconv...
304
  					mutex_unlock(&tosh_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
305
306
307
308
  					break;
  				}
  			}
  			err = tosh_smm(&regs);
613655fa3   Arnd Bergmann   drivers: autoconv...
309
  			mutex_unlock(&tosh_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
  			break;
  		default:
  			return -EINVAL;
  	}
  
          if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
          	return -EFAULT;
  
  	return (err==0) ? 0:-EINVAL;
  }
  
  
  /*
   * Print the information for /proc/toshiba
   */
  #ifdef CONFIG_PROC_FS
967bb77c6   Alexey Dobriyan   [PATCH] seq_file ...
326
  static int proc_toshiba_show(struct seq_file *m, void *v)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
327
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
328
  	int key;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
329
330
331
332
333
334
335
336
337
338
  	key = tosh_fn_status();
  
  	/* Arguments
  	     0) Linux driver version (this will change if format changes)
  	     1) Machine ID
  	     2) SCI version
  	     3) BIOS version (major, minor)
  	     4) BIOS date (in SCI date format)
  	     5) Fn Key status
  	*/
967bb77c6   Alexey Dobriyan   [PATCH] seq_file ...
339
340
  	seq_printf(m, "1.1 0x%04x %d.%d %d.%d 0x%04x 0x%02x
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
341
342
343
344
345
346
347
  		tosh_id,
  		(tosh_sci & 0xff00)>>8,
  		tosh_sci & 0xff,
  		(tosh_bios & 0xff00)>>8,
  		tosh_bios & 0xff,
  		tosh_date,
  		key);
967bb77c6   Alexey Dobriyan   [PATCH] seq_file ...
348
349
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350

967bb77c6   Alexey Dobriyan   [PATCH] seq_file ...
351
352
353
  static int proc_toshiba_open(struct inode *inode, struct file *file)
  {
  	return single_open(file, proc_toshiba_show, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
354
  }
967bb77c6   Alexey Dobriyan   [PATCH] seq_file ...
355
356
357
358
359
360
361
362
  
  static const struct file_operations proc_toshiba_fops = {
  	.owner		= THIS_MODULE,
  	.open		= proc_toshiba_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
  #endif
  
  
  /*
   * Determine which port to use for the Fn key status
   */
  static void tosh_set_fn_port(void)
  {
  	switch (tosh_id) {
  		case 0xfc02: case 0xfc04: case 0xfc09: case 0xfc0a: case 0xfc10:
  		case 0xfc11: case 0xfc13: case 0xfc15: case 0xfc1a: case 0xfc1b:
  		case 0xfc5a:
  			tosh_fn = 0x62;
  			break;
  		case 0xfc08: case 0xfc17: case 0xfc1d: case 0xfcd1: case 0xfce0:
  		case 0xfce2:
  			tosh_fn = 0x68;
  			break;
  		default:
  			tosh_fn = 0x00;
  			break;
  	}
  
  	return;
  }
  
  
  /*
   * Get the machine identification number of the current model
   */
ef5a4c8b0   Al Viro   [PATCH] remove IS...
393
  static int tosh_get_machine_id(void __iomem *bios)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
394
395
396
397
398
  {
  	int id;
  	SMMRegisters regs;
  	unsigned short bx,cx;
  	unsigned long address;
ef5a4c8b0   Al Viro   [PATCH] remove IS...
399
  	id = (0x100*(int) readb(bios+0xfffe))+((int) readb(bios+0xfffa));
3f5f7e2ee   Dmitry Torokhov   [PATCH] Toshiba d...
400

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
  	/* do we have a SCTTable machine identication number on our hands */
  
  	if (id==0xfc2f) {
  
  		/* start by getting a pointer into the BIOS */
  
  		regs.eax = 0xc000;
  		regs.ebx = 0x0000;
  		regs.ecx = 0x0000;
  		tosh_smm(&regs);
  		bx = (unsigned short) (regs.ebx & 0xffff);
  
  		/* At this point in the Toshiba routines under MS Windows
  		   the bx register holds 0xe6f5. However my code is producing
  		   a different value! For the time being I will just fudge the
  		   value. This has been verified on a Satellite Pro 430CDT,
  		   Tecra 750CDT, Tecra 780DVD and Satellite 310CDT. */
  #if TOSH_DEBUG
  		printk("toshiba: debugging ID ebx=0x%04x
  ", regs.ebx);
  #endif
  		bx = 0xe6f5;
  
  		/* now twiddle with our pointer a bit */
ef5a4c8b0   Al Viro   [PATCH] remove IS...
425
426
427
428
429
430
  		address = bx;
  		cx = readw(bios + address);
  		address = 9+bx+cx;
  		cx = readw(bios + address);
  		address = 0xa+cx;
  		cx = readw(bios + address);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
  
  		/* now construct our machine identification number */
  
  		id = ((cx & 0xff)<<8)+((cx & 0xff00)>>8);
  	}
  
  	return id;
  }
  
  
  /*
   * Probe for the presence of a Toshiba laptop
   *
   *   returns and non-zero if unable to detect the presence of a Toshiba
   *   laptop, otherwise zero and determines the Machine ID, BIOS version and
   *   date, and SCI version.
   */
  static int tosh_probe(void)
  {
  	int i,major,minor,day,year,month,flag;
  	unsigned char signature[7] = { 0x54,0x4f,0x53,0x48,0x49,0x42,0x41 };
  	SMMRegisters regs;
1dcf83fd0   Alan Cox   toshiba: use iore...
453
  	void __iomem *bios = ioremap_cache(0xf0000, 0x10000);
ef5a4c8b0   Al Viro   [PATCH] remove IS...
454
455
456
  
  	if (!bios)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
457
458
459
460
461
  
  	/* extra sanity check for the string "TOSHIBA" in the BIOS because
  	   some machines that are not Toshiba's pass the next test */
  
  	for (i=0;i<7;i++) {
ef5a4c8b0   Al Viro   [PATCH] remove IS...
462
  		if (readb(bios+0xe010+i)!=signature[i]) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
463
464
  			printk("toshiba: not a supported Toshiba laptop
  ");
ef5a4c8b0   Al Viro   [PATCH] remove IS...
465
  			iounmap(bios);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
466
467
468
469
470
  			return -ENODEV;
  		}
  	}
  
  	/* call the Toshiba SCI support check routine */
3f5f7e2ee   Dmitry Torokhov   [PATCH] Toshiba d...
471

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
472
473
474
475
476
477
478
479
480
481
  	regs.eax = 0xf0f0;
  	regs.ebx = 0x0000;
  	regs.ecx = 0x0000;
  	flag = tosh_smm(&regs);
  
  	/* if this is not a Toshiba laptop carry flag is set and ah=0x86 */
  
  	if ((flag==1) || ((regs.eax & 0xff00)==0x8600)) {
  		printk("toshiba: not a supported Toshiba laptop
  ");
ef5a4c8b0   Al Viro   [PATCH] remove IS...
482
  		iounmap(bios);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
483
484
485
486
487
488
  		return -ENODEV;
  	}
  
  	/* if we get this far then we are running on a Toshiba (probably)! */
  
  	tosh_sci = regs.edx & 0xffff;
3f5f7e2ee   Dmitry Torokhov   [PATCH] Toshiba d...
489

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
490
  	/* next get the machine ID of the current laptop */
ef5a4c8b0   Al Viro   [PATCH] remove IS...
491
  	tosh_id = tosh_get_machine_id(bios);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
492
493
  
  	/* get the BIOS version */
ef5a4c8b0   Al Viro   [PATCH] remove IS...
494
495
  	major = readb(bios+0xe009)-'0';
  	minor = ((readb(bios+0xe00b)-'0')*10)+(readb(bios+0xe00c)-'0');
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
496
497
498
  	tosh_bios = (major*0x100)+minor;
  
  	/* get the BIOS date */
ef5a4c8b0   Al Viro   [PATCH] remove IS...
499
500
501
  	day = ((readb(bios+0xfff5)-'0')*10)+(readb(bios+0xfff6)-'0');
  	month = ((readb(bios+0xfff8)-'0')*10)+(readb(bios+0xfff9)-'0');
  	year = ((readb(bios+0xfffb)-'0')*10)+(readb(bios+0xfffc)-'0');
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
  	tosh_date = (((year-90) & 0x1f)<<10) | ((month & 0xf)<<6)
  		| ((day & 0x1f)<<1);
  
  
  	/* in theory we should check the ports we are going to use for the
  	   fn key detection (and the fan on the Portage 610/Tecra700), and
  	   then request them to stop other drivers using them. However as
  	   the keyboard driver grabs 0x60-0x6f and the pic driver grabs
  	   0xa0-0xbf we can't. We just have to live dangerously and use the
  	   ports anyway, oh boy! */
  
  	/* do we need to emulate the fan? */
  
  	if ((tosh_id==0xfccb) || (tosh_id==0xfccc))
  		tosh_fan = 1;
ef5a4c8b0   Al Viro   [PATCH] remove IS...
517
  	iounmap(bios);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
518
519
  	return 0;
  }
3f5f7e2ee   Dmitry Torokhov   [PATCH] Toshiba d...
520
  static int __init toshiba_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
521
522
523
  {
  	int retval;
  	/* are we running on a Toshiba laptop */
3f5f7e2ee   Dmitry Torokhov   [PATCH] Toshiba d...
524
525
  	if (tosh_probe())
  		return -ENODEV;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
526

8dfba4d71   Joe Perches   drivers/char/: Sp...
527
528
  	printk(KERN_INFO "Toshiba System Management Mode driver v" TOSH_VERSION "
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
529
530
531
532
533
534
535
  
  	/* set the port to use for Fn status if not specified as a parameter */
  	if (tosh_fn==0x00)
  		tosh_set_fn_port();
  
  	/* register the device file */
  	retval = misc_register(&tosh_device);
3f5f7e2ee   Dmitry Torokhov   [PATCH] Toshiba d...
536
  	if (retval < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
537
538
539
  		return retval;
  
  #ifdef CONFIG_PROC_FS
967bb77c6   Alexey Dobriyan   [PATCH] seq_file ...
540
541
  	{
  		struct proc_dir_entry *pde;
1b5022173   Denis V. Lunev   drivers: use non-...
542
  		pde = proc_create("toshiba", 0, NULL, &proc_toshiba_fops);
967bb77c6   Alexey Dobriyan   [PATCH] seq_file ...
543
544
545
546
  		if (!pde) {
  			misc_deregister(&tosh_device);
  			return -ENOMEM;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
547
548
549
550
551
  	}
  #endif
  
  	return 0;
  }
3f5f7e2ee   Dmitry Torokhov   [PATCH] Toshiba d...
552
  static void __exit toshiba_exit(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
553
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
554
  	remove_proc_entry("toshiba", NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
555
556
  	misc_deregister(&tosh_device);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
557

3f5f7e2ee   Dmitry Torokhov   [PATCH] Toshiba d...
558
559
  module_init(toshiba_init);
  module_exit(toshiba_exit);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
560