Thomas Gleixner | 2e97506 | 2019-05-24 12:03:49 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* toshiba.c -- Linux driver for accessing the SMM on Toshiba laptops |
| 3 | * |
| 4 | * Copyright (c) 1996-2001 Jonathan A. Buzzard (jonathan@buzzard.org.uk) |
| 5 | * |
| 6 | * Valuable assistance and patches from: |
| 7 | * Tom May <tom@you-bastards.com> |
| 8 | * Rob Napier <rnapier@employees.org> |
| 9 | * |
| 10 | * Fn status port numbers for machine ID's courtesy of |
| 11 | * 0xfc02: Scott Eisert <scott.e@sky-eye.com> |
| 12 | * 0xfc04: Steve VanDevender <stevev@efn.org> |
| 13 | * 0xfc08: Garth Berry <garth@itsbruce.net> |
| 14 | * 0xfc0a: Egbert Eich <eich@xfree86.org> |
| 15 | * 0xfc10: Andrew Lofthouse <Andrew.Lofthouse@robins.af.mil> |
| 16 | * 0xfc11: Spencer Olson <solson@novell.com> |
| 17 | * 0xfc13: Claudius Frankewitz <kryp@gmx.de> |
| 18 | * 0xfc15: Tom May <tom@you-bastards.com> |
| 19 | * 0xfc17: Dave Konrad <konrad@xenia.it> |
| 20 | * 0xfc1a: George Betzos <betzos@engr.colostate.edu> |
| 21 | * 0xfc1b: Munemasa Wada <munemasa@jnovel.co.jp> |
| 22 | * 0xfc1d: Arthur Liu <armie@slap.mine.nu> |
| 23 | * 0xfc5a: Jacques L'helgoualc'h <lhh@free.fr> |
| 24 | * 0xfcd1: Mr. Dave Konrad <konrad@xenia.it> |
| 25 | * |
| 26 | * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING |
| 27 | * |
| 28 | * This code is covered by the GNU GPL and you are free to make any |
| 29 | * changes you wish to it under the terms of the license. However the |
| 30 | * code has the potential to render your computer and/or someone else's |
| 31 | * unusable. Please proceed with care when modifying the code. |
| 32 | * |
| 33 | * Note: Unfortunately the laptop hardware can close the System Configuration |
| 34 | * Interface on it's own accord. It is therefore necessary for *all* |
| 35 | * programs using this driver to be aware that *any* SCI call can fail at |
| 36 | * *any* time. It is up to any program to be aware of this eventuality |
| 37 | * and take appropriate steps. |
| 38 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | * The information used to write this driver has been obtained by reverse |
| 40 | * engineering the software supplied by Toshiba for their portable computers in |
| 41 | * strict accordance with the European Council Directive 92/250/EEC on the legal |
| 42 | * protection of computer programs, and it's implementation into English Law by |
| 43 | * the Copyright (Computer Programs) Regulations 1992 (S.I. 1992 No.3233). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | */ |
| 45 | |
| 46 | #define TOSH_VERSION "1.11 26/9/2001" |
| 47 | #define TOSH_DEBUG 0 |
| 48 | |
| 49 | #include <linux/module.h> |
| 50 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/types.h> |
| 52 | #include <linux/fcntl.h> |
| 53 | #include <linux/miscdevice.h> |
| 54 | #include <linux/ioport.h> |
| 55 | #include <asm/io.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 56 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <linux/init.h> |
| 58 | #include <linux/stat.h> |
| 59 | #include <linux/proc_fs.h> |
Alexey Dobriyan | 967bb77 | 2007-02-10 01:46:15 -0800 | [diff] [blame] | 60 | #include <linux/seq_file.h> |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 61 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include <linux/toshiba.h> |
| 63 | |
| 64 | #define TOSH_MINOR_DEV 181 |
| 65 | |
Dmitry Torokhov | 3f5f7e2 | 2005-06-25 14:54:22 -0700 | [diff] [blame] | 66 | MODULE_LICENSE("GPL"); |
| 67 | MODULE_AUTHOR("Jonathan Buzzard <jonathan@buzzard.org.uk>"); |
| 68 | MODULE_DESCRIPTION("Toshiba laptop SMM driver"); |
| 69 | MODULE_SUPPORTED_DEVICE("toshiba"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 71 | static DEFINE_MUTEX(tosh_mutex); |
Dmitry Torokhov | 3f5f7e2 | 2005-06-25 14:54:22 -0700 | [diff] [blame] | 72 | static int tosh_fn; |
| 73 | module_param_named(fn, tosh_fn, int, 0); |
| 74 | MODULE_PARM_DESC(fn, "User specified Fn key detection port"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Dmitry Torokhov | 3f5f7e2 | 2005-06-25 14:54:22 -0700 | [diff] [blame] | 76 | static int tosh_id; |
| 77 | static int tosh_bios; |
| 78 | static int tosh_date; |
| 79 | static int tosh_sci; |
| 80 | static int tosh_fan; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Alan Cox | 3e8d95d | 2010-01-04 16:19:55 +0000 | [diff] [blame] | 82 | static long tosh_ioctl(struct file *, unsigned int, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | unsigned long); |
| 84 | |
| 85 | |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 86 | static const struct file_operations tosh_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | .owner = THIS_MODULE, |
Alan Cox | 3e8d95d | 2010-01-04 16:19:55 +0000 | [diff] [blame] | 88 | .unlocked_ioctl = tosh_ioctl, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 89 | .llseek = noop_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | static struct miscdevice tosh_device = { |
| 93 | TOSH_MINOR_DEV, |
| 94 | "toshiba", |
| 95 | &tosh_fops |
| 96 | }; |
| 97 | |
| 98 | /* |
| 99 | * Read the Fn key status |
| 100 | */ |
| 101 | #ifdef CONFIG_PROC_FS |
| 102 | static int tosh_fn_status(void) |
| 103 | { |
| 104 | unsigned char scan; |
| 105 | unsigned long flags; |
| 106 | |
| 107 | if (tosh_fn!=0) { |
| 108 | scan = inb(tosh_fn); |
| 109 | } else { |
| 110 | local_irq_save(flags); |
| 111 | outb(0x8e, 0xe4); |
| 112 | scan = inb(0xe5); |
| 113 | local_irq_restore(flags); |
| 114 | } |
| 115 | |
| 116 | return (int) scan; |
| 117 | } |
| 118 | #endif |
| 119 | |
| 120 | |
| 121 | /* |
| 122 | * For the Portage 610CT and the Tecra 700CS/700CDT emulate the HCI fan function |
| 123 | */ |
| 124 | static int tosh_emulate_fan(SMMRegisters *regs) |
| 125 | { |
| 126 | unsigned long eax,ecx,flags; |
| 127 | unsigned char al; |
| 128 | |
| 129 | eax = regs->eax & 0xff00; |
| 130 | ecx = regs->ecx & 0xffff; |
| 131 | |
| 132 | /* Portage 610CT */ |
| 133 | |
| 134 | if (tosh_id==0xfccb) { |
| 135 | if (eax==0xfe00) { |
| 136 | /* fan status */ |
| 137 | local_irq_save(flags); |
| 138 | outb(0xbe, 0xe4); |
| 139 | al = inb(0xe5); |
| 140 | local_irq_restore(flags); |
| 141 | regs->eax = 0x00; |
| 142 | regs->ecx = (unsigned int) (al & 0x01); |
| 143 | } |
| 144 | if ((eax==0xff00) && (ecx==0x0000)) { |
| 145 | /* fan off */ |
| 146 | local_irq_save(flags); |
| 147 | outb(0xbe, 0xe4); |
| 148 | al = inb(0xe5); |
| 149 | outb(0xbe, 0xe4); |
| 150 | outb (al | 0x01, 0xe5); |
| 151 | local_irq_restore(flags); |
| 152 | regs->eax = 0x00; |
| 153 | regs->ecx = 0x00; |
| 154 | } |
| 155 | if ((eax==0xff00) && (ecx==0x0001)) { |
| 156 | /* fan on */ |
| 157 | local_irq_save(flags); |
| 158 | outb(0xbe, 0xe4); |
| 159 | al = inb(0xe5); |
| 160 | outb(0xbe, 0xe4); |
| 161 | outb(al & 0xfe, 0xe5); |
| 162 | local_irq_restore(flags); |
| 163 | regs->eax = 0x00; |
| 164 | regs->ecx = 0x01; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /* Tecra 700CS/CDT */ |
| 169 | |
| 170 | if (tosh_id==0xfccc) { |
| 171 | if (eax==0xfe00) { |
| 172 | /* fan status */ |
| 173 | local_irq_save(flags); |
| 174 | outb(0xe0, 0xe4); |
| 175 | al = inb(0xe5); |
| 176 | local_irq_restore(flags); |
| 177 | regs->eax = 0x00; |
| 178 | regs->ecx = al & 0x01; |
| 179 | } |
| 180 | if ((eax==0xff00) && (ecx==0x0000)) { |
| 181 | /* fan off */ |
| 182 | local_irq_save(flags); |
| 183 | outb(0xe0, 0xe4); |
| 184 | al = inb(0xe5); |
| 185 | outw(0xe0 | ((al & 0xfe) << 8), 0xe4); |
| 186 | local_irq_restore(flags); |
| 187 | regs->eax = 0x00; |
| 188 | regs->ecx = 0x00; |
| 189 | } |
| 190 | if ((eax==0xff00) && (ecx==0x0001)) { |
| 191 | /* fan on */ |
| 192 | local_irq_save(flags); |
| 193 | outb(0xe0, 0xe4); |
| 194 | al = inb(0xe5); |
| 195 | outw(0xe0 | ((al | 0x01) << 8), 0xe4); |
| 196 | local_irq_restore(flags); |
| 197 | regs->eax = 0x00; |
| 198 | regs->ecx = 0x01; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | |
| 206 | /* |
| 207 | * Put the laptop into System Management Mode |
| 208 | */ |
| 209 | int tosh_smm(SMMRegisters *regs) |
| 210 | { |
| 211 | int eax; |
| 212 | |
| 213 | asm ("# load the values into the registers\n\t" \ |
| 214 | "pushl %%eax\n\t" \ |
| 215 | "movl 0(%%eax),%%edx\n\t" \ |
| 216 | "push %%edx\n\t" \ |
| 217 | "movl 4(%%eax),%%ebx\n\t" \ |
| 218 | "movl 8(%%eax),%%ecx\n\t" \ |
| 219 | "movl 12(%%eax),%%edx\n\t" \ |
| 220 | "movl 16(%%eax),%%esi\n\t" \ |
| 221 | "movl 20(%%eax),%%edi\n\t" \ |
| 222 | "popl %%eax\n\t" \ |
| 223 | "# call the System Management mode\n\t" \ |
| 224 | "inb $0xb2,%%al\n\t" |
| 225 | "# fill out the memory with the values in the registers\n\t" \ |
| 226 | "xchgl %%eax,(%%esp)\n\t" |
| 227 | "movl %%ebx,4(%%eax)\n\t" \ |
| 228 | "movl %%ecx,8(%%eax)\n\t" \ |
| 229 | "movl %%edx,12(%%eax)\n\t" \ |
| 230 | "movl %%esi,16(%%eax)\n\t" \ |
| 231 | "movl %%edi,20(%%eax)\n\t" \ |
| 232 | "popl %%edx\n\t" \ |
| 233 | "movl %%edx,0(%%eax)\n\t" \ |
| 234 | "# setup the return value to the carry flag\n\t" \ |
| 235 | "lahf\n\t" \ |
| 236 | "shrl $8,%%eax\n\t" \ |
| 237 | "andl $1,%%eax\n" \ |
| 238 | : "=a" (eax) |
| 239 | : "a" (regs) |
| 240 | : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); |
| 241 | |
| 242 | return eax; |
| 243 | } |
Randy Dunlap | 0bf9322 | 2006-12-06 20:38:41 -0800 | [diff] [blame] | 244 | EXPORT_SYMBOL(tosh_smm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
| 246 | |
Alan Cox | 3e8d95d | 2010-01-04 16:19:55 +0000 | [diff] [blame] | 247 | static long tosh_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
| 249 | SMMRegisters regs; |
| 250 | SMMRegisters __user *argp = (SMMRegisters __user *)arg; |
| 251 | unsigned short ax,bx; |
| 252 | int err; |
| 253 | |
| 254 | if (!argp) |
| 255 | return -EINVAL; |
| 256 | |
| 257 | if (copy_from_user(®s, argp, sizeof(SMMRegisters))) |
| 258 | return -EFAULT; |
| 259 | |
| 260 | switch (cmd) { |
| 261 | case TOSH_SMM: |
| 262 | ax = regs.eax & 0xff00; |
| 263 | bx = regs.ebx & 0xffff; |
| 264 | /* block HCI calls to read/write memory & PCI devices */ |
| 265 | if (((ax==0xff00) || (ax==0xfe00)) && (bx>0x0069)) |
| 266 | return -EINVAL; |
| 267 | |
| 268 | /* do we need to emulate the fan ? */ |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 269 | mutex_lock(&tosh_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | if (tosh_fan==1) { |
| 271 | if (((ax==0xf300) || (ax==0xf400)) && (bx==0x0004)) { |
| 272 | err = tosh_emulate_fan(®s); |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 273 | mutex_unlock(&tosh_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | break; |
| 275 | } |
| 276 | } |
| 277 | err = tosh_smm(®s); |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 278 | mutex_unlock(&tosh_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | break; |
| 280 | default: |
| 281 | return -EINVAL; |
| 282 | } |
| 283 | |
| 284 | if (copy_to_user(argp, ®s, sizeof(SMMRegisters))) |
| 285 | return -EFAULT; |
| 286 | |
| 287 | return (err==0) ? 0:-EINVAL; |
| 288 | } |
| 289 | |
| 290 | |
| 291 | /* |
| 292 | * Print the information for /proc/toshiba |
| 293 | */ |
| 294 | #ifdef CONFIG_PROC_FS |
Alexey Dobriyan | 967bb77 | 2007-02-10 01:46:15 -0800 | [diff] [blame] | 295 | static int proc_toshiba_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | int key; |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | key = tosh_fn_status(); |
| 300 | |
| 301 | /* Arguments |
| 302 | 0) Linux driver version (this will change if format changes) |
| 303 | 1) Machine ID |
| 304 | 2) SCI version |
| 305 | 3) BIOS version (major, minor) |
| 306 | 4) BIOS date (in SCI date format) |
| 307 | 5) Fn Key status |
| 308 | */ |
Alexey Dobriyan | 967bb77 | 2007-02-10 01:46:15 -0800 | [diff] [blame] | 309 | seq_printf(m, "1.1 0x%04x %d.%d %d.%d 0x%04x 0x%02x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | tosh_id, |
| 311 | (tosh_sci & 0xff00)>>8, |
| 312 | tosh_sci & 0xff, |
| 313 | (tosh_bios & 0xff00)>>8, |
| 314 | tosh_bios & 0xff, |
| 315 | tosh_date, |
| 316 | key); |
Alexey Dobriyan | 967bb77 | 2007-02-10 01:46:15 -0800 | [diff] [blame] | 317 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | #endif |
| 320 | |
| 321 | |
| 322 | /* |
| 323 | * Determine which port to use for the Fn key status |
| 324 | */ |
| 325 | static void tosh_set_fn_port(void) |
| 326 | { |
| 327 | switch (tosh_id) { |
| 328 | case 0xfc02: case 0xfc04: case 0xfc09: case 0xfc0a: case 0xfc10: |
| 329 | case 0xfc11: case 0xfc13: case 0xfc15: case 0xfc1a: case 0xfc1b: |
| 330 | case 0xfc5a: |
| 331 | tosh_fn = 0x62; |
| 332 | break; |
| 333 | case 0xfc08: case 0xfc17: case 0xfc1d: case 0xfcd1: case 0xfce0: |
| 334 | case 0xfce2: |
| 335 | tosh_fn = 0x68; |
| 336 | break; |
| 337 | default: |
| 338 | tosh_fn = 0x00; |
| 339 | break; |
| 340 | } |
| 341 | |
| 342 | return; |
| 343 | } |
| 344 | |
| 345 | |
| 346 | /* |
| 347 | * Get the machine identification number of the current model |
| 348 | */ |
Al Viro | ef5a4c8 | 2006-03-24 03:15:36 -0800 | [diff] [blame] | 349 | static int tosh_get_machine_id(void __iomem *bios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { |
| 351 | int id; |
| 352 | SMMRegisters regs; |
| 353 | unsigned short bx,cx; |
| 354 | unsigned long address; |
| 355 | |
Al Viro | ef5a4c8 | 2006-03-24 03:15:36 -0800 | [diff] [blame] | 356 | id = (0x100*(int) readb(bios+0xfffe))+((int) readb(bios+0xfffa)); |
Dmitry Torokhov | 3f5f7e2 | 2005-06-25 14:54:22 -0700 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | /* do we have a SCTTable machine identication number on our hands */ |
| 359 | |
| 360 | if (id==0xfc2f) { |
| 361 | |
| 362 | /* start by getting a pointer into the BIOS */ |
| 363 | |
| 364 | regs.eax = 0xc000; |
| 365 | regs.ebx = 0x0000; |
| 366 | regs.ecx = 0x0000; |
| 367 | tosh_smm(®s); |
| 368 | bx = (unsigned short) (regs.ebx & 0xffff); |
| 369 | |
| 370 | /* At this point in the Toshiba routines under MS Windows |
| 371 | the bx register holds 0xe6f5. However my code is producing |
| 372 | a different value! For the time being I will just fudge the |
| 373 | value. This has been verified on a Satellite Pro 430CDT, |
| 374 | Tecra 750CDT, Tecra 780DVD and Satellite 310CDT. */ |
| 375 | #if TOSH_DEBUG |
| 376 | printk("toshiba: debugging ID ebx=0x%04x\n", regs.ebx); |
| 377 | #endif |
| 378 | bx = 0xe6f5; |
| 379 | |
| 380 | /* now twiddle with our pointer a bit */ |
| 381 | |
Al Viro | ef5a4c8 | 2006-03-24 03:15:36 -0800 | [diff] [blame] | 382 | address = bx; |
| 383 | cx = readw(bios + address); |
| 384 | address = 9+bx+cx; |
| 385 | cx = readw(bios + address); |
| 386 | address = 0xa+cx; |
| 387 | cx = readw(bios + address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | /* now construct our machine identification number */ |
| 390 | |
| 391 | id = ((cx & 0xff)<<8)+((cx & 0xff00)>>8); |
| 392 | } |
| 393 | |
| 394 | return id; |
| 395 | } |
| 396 | |
| 397 | |
| 398 | /* |
| 399 | * Probe for the presence of a Toshiba laptop |
| 400 | * |
| 401 | * returns and non-zero if unable to detect the presence of a Toshiba |
| 402 | * laptop, otherwise zero and determines the Machine ID, BIOS version and |
| 403 | * date, and SCI version. |
| 404 | */ |
| 405 | static int tosh_probe(void) |
| 406 | { |
| 407 | int i,major,minor,day,year,month,flag; |
| 408 | unsigned char signature[7] = { 0x54,0x4f,0x53,0x48,0x49,0x42,0x41 }; |
| 409 | SMMRegisters regs; |
Dan Williams | 4816693 | 2015-07-30 12:54:40 -0400 | [diff] [blame] | 410 | void __iomem *bios = ioremap(0xf0000, 0x10000); |
Al Viro | ef5a4c8 | 2006-03-24 03:15:36 -0800 | [diff] [blame] | 411 | |
| 412 | if (!bios) |
| 413 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | /* extra sanity check for the string "TOSHIBA" in the BIOS because |
| 416 | some machines that are not Toshiba's pass the next test */ |
| 417 | |
| 418 | for (i=0;i<7;i++) { |
Al Viro | ef5a4c8 | 2006-03-24 03:15:36 -0800 | [diff] [blame] | 419 | if (readb(bios+0xe010+i)!=signature[i]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | printk("toshiba: not a supported Toshiba laptop\n"); |
Al Viro | ef5a4c8 | 2006-03-24 03:15:36 -0800 | [diff] [blame] | 421 | iounmap(bios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | return -ENODEV; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | /* call the Toshiba SCI support check routine */ |
Dmitry Torokhov | 3f5f7e2 | 2005-06-25 14:54:22 -0700 | [diff] [blame] | 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | regs.eax = 0xf0f0; |
| 429 | regs.ebx = 0x0000; |
| 430 | regs.ecx = 0x0000; |
| 431 | flag = tosh_smm(®s); |
| 432 | |
| 433 | /* if this is not a Toshiba laptop carry flag is set and ah=0x86 */ |
| 434 | |
| 435 | if ((flag==1) || ((regs.eax & 0xff00)==0x8600)) { |
| 436 | printk("toshiba: not a supported Toshiba laptop\n"); |
Al Viro | ef5a4c8 | 2006-03-24 03:15:36 -0800 | [diff] [blame] | 437 | iounmap(bios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | return -ENODEV; |
| 439 | } |
| 440 | |
| 441 | /* if we get this far then we are running on a Toshiba (probably)! */ |
| 442 | |
| 443 | tosh_sci = regs.edx & 0xffff; |
Dmitry Torokhov | 3f5f7e2 | 2005-06-25 14:54:22 -0700 | [diff] [blame] | 444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | /* next get the machine ID of the current laptop */ |
| 446 | |
Al Viro | ef5a4c8 | 2006-03-24 03:15:36 -0800 | [diff] [blame] | 447 | tosh_id = tosh_get_machine_id(bios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | /* get the BIOS version */ |
| 450 | |
Al Viro | ef5a4c8 | 2006-03-24 03:15:36 -0800 | [diff] [blame] | 451 | major = readb(bios+0xe009)-'0'; |
| 452 | minor = ((readb(bios+0xe00b)-'0')*10)+(readb(bios+0xe00c)-'0'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | tosh_bios = (major*0x100)+minor; |
| 454 | |
| 455 | /* get the BIOS date */ |
| 456 | |
Al Viro | ef5a4c8 | 2006-03-24 03:15:36 -0800 | [diff] [blame] | 457 | day = ((readb(bios+0xfff5)-'0')*10)+(readb(bios+0xfff6)-'0'); |
| 458 | month = ((readb(bios+0xfff8)-'0')*10)+(readb(bios+0xfff9)-'0'); |
| 459 | year = ((readb(bios+0xfffb)-'0')*10)+(readb(bios+0xfffc)-'0'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | tosh_date = (((year-90) & 0x1f)<<10) | ((month & 0xf)<<6) |
| 461 | | ((day & 0x1f)<<1); |
| 462 | |
| 463 | |
| 464 | /* in theory we should check the ports we are going to use for the |
| 465 | fn key detection (and the fan on the Portage 610/Tecra700), and |
| 466 | then request them to stop other drivers using them. However as |
| 467 | the keyboard driver grabs 0x60-0x6f and the pic driver grabs |
| 468 | 0xa0-0xbf we can't. We just have to live dangerously and use the |
| 469 | ports anyway, oh boy! */ |
| 470 | |
| 471 | /* do we need to emulate the fan? */ |
| 472 | |
| 473 | if ((tosh_id==0xfccb) || (tosh_id==0xfccc)) |
| 474 | tosh_fan = 1; |
| 475 | |
Al Viro | ef5a4c8 | 2006-03-24 03:15:36 -0800 | [diff] [blame] | 476 | iounmap(bios); |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return 0; |
| 479 | } |
| 480 | |
Dmitry Torokhov | 3f5f7e2 | 2005-06-25 14:54:22 -0700 | [diff] [blame] | 481 | static int __init toshiba_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
| 483 | int retval; |
| 484 | /* are we running on a Toshiba laptop */ |
| 485 | |
Dmitry Torokhov | 3f5f7e2 | 2005-06-25 14:54:22 -0700 | [diff] [blame] | 486 | if (tosh_probe()) |
| 487 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
Joe Perches | 8dfba4d | 2008-02-03 17:11:42 +0200 | [diff] [blame] | 489 | printk(KERN_INFO "Toshiba System Management Mode driver v" TOSH_VERSION "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
| 491 | /* set the port to use for Fn status if not specified as a parameter */ |
| 492 | if (tosh_fn==0x00) |
| 493 | tosh_set_fn_port(); |
| 494 | |
| 495 | /* register the device file */ |
| 496 | retval = misc_register(&tosh_device); |
Dmitry Torokhov | 3f5f7e2 | 2005-06-25 14:54:22 -0700 | [diff] [blame] | 497 | if (retval < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | return retval; |
| 499 | |
| 500 | #ifdef CONFIG_PROC_FS |
Alexey Dobriyan | 967bb77 | 2007-02-10 01:46:15 -0800 | [diff] [blame] | 501 | { |
| 502 | struct proc_dir_entry *pde; |
| 503 | |
Christoph Hellwig | 3f3942a | 2018-05-15 15:57:23 +0200 | [diff] [blame] | 504 | pde = proc_create_single("toshiba", 0, NULL, proc_toshiba_show); |
Alexey Dobriyan | 967bb77 | 2007-02-10 01:46:15 -0800 | [diff] [blame] | 505 | if (!pde) { |
| 506 | misc_deregister(&tosh_device); |
| 507 | return -ENOMEM; |
| 508 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
| 510 | #endif |
| 511 | |
| 512 | return 0; |
| 513 | } |
| 514 | |
Dmitry Torokhov | 3f5f7e2 | 2005-06-25 14:54:22 -0700 | [diff] [blame] | 515 | static void __exit toshiba_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | remove_proc_entry("toshiba", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | misc_deregister(&tosh_device); |
| 519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Dmitry Torokhov | 3f5f7e2 | 2005-06-25 14:54:22 -0700 | [diff] [blame] | 521 | module_init(toshiba_init); |
| 522 | module_exit(toshiba_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |