wmauda: Fix installation dir
[dockapps.git] / wmpower-0.4.3 / src / power_management / toshiba / sci.c
blob96ed5af91a8b0ce13ad0c9efb54b0c030f42a879
1 /* sci.c -- System Configuration Interface
3 * Copyright (c) 1998-2000 Jonathan A. Buzzard (jonathan@buzzard.org.uk)
4 *
5 * $Log: sci.c,v $
6 * Revision 1.1 2003/09/18 16:38:27 noberasco
7 * overhaul III
9 * Revision 1.1.1.1 2003/06/05 09:34:03 noberasco
10 * Initial import.
12 * Revision 1.14 2001/10/05 13:07:40 jab
13 * checked in changes for kernel module
15 * Revision 1.13 1999/12/18 14:32:24 jab
16 * fixed some bugs in the assembler
17 * removed the SciGetModel function, not needed now with working MachineID
19 * Revision 1.12 1999/11/17 16:00:42 jab
20 * changed assembler to manually save registers, hopefully this should
21 * make the programs more stable
23 * Revision 1.11 1999/07/25 14:39:49 jab
24 * fixed bugs in SciOpenInterface and SciSetPassword
25 * updated email address
27 * Revision 1.10 1999/03/11 20:22:14 jab
28 * changed get and set routines to use SciRegisters
30 * Revision 1.9 1999/03/06 16:46:30 jab
31 * moved the BiosVersion and MachineID functions to hci.c
33 * Revision 1.8 1998/09/07 18:23:36 jab
34 * removed SciGetMachineID2 as no longer required
35 * added a routine to extract the model string from the BIOS
37 * Revision 1.7 1998/09/04 18:14:31 jab
38 * fixed the compile warning about rcsid
40 * Revision 1.6 1998/08/24 18:05:04 jab
41 * implemented the SciGetBiosVersion function
43 * Revision 1.5 1998/08/23 12:16:45 jab
44 * fixed the SciACPower function so it now works
46 * Revision 1.4 1998/08/19 08:45:10 jab
47 * changed GetMachineId to return SCI_SUCCESS/SCI_FAILURE
49 * Revision 1.3 1998/08/18 16:54:54 jab
50 * fixes to SciGetMachineId curtesy of Patrick Reyonlds <patrick@cs.virgina.edu>
52 * Revision 1.2 1998/08/06 08:27:14 jab
53 * prepended all functions with Sci
55 * Revision 1.1 1998/05/23 08:08:53 jab
56 * Initial revision
59 * This program is free software; you can redistribute it and/or modify
60 * it under the terms of the GNU General Public License as published by
61 * the Free Software Foundation; either version 2 of the License, or
62 * (at your option) any later version.
64 * This program is distributed in the hope that it will be useful,
65 * but WITHOUT ANY WARRANTY; without even the implied warranty of
66 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67 * GNU General Public License for more details.
69 * You should have received a copy of the GNU General Public License
70 * along with this program; if not, write to the Free Software
71 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
75 static const char rcsid[]="$Id: sci.c,v 1.1 2003/09/18 16:38:27 noberasco Exp $";
77 #include<stdio.h>
78 #include<stdlib.h>
79 #include<unistd.h>
80 #include<fcntl.h>
81 #include<sys/stat.h>
82 #include<sys/ioctl.h>
84 #include"sci.h"
88 * Is this a supported Machine? (ie. is it a Toshiba)
90 int SciSupportCheck(int *version)
92 SMMRegisters regs;
93 int fd;
95 if ((fd=open(TOSH_DEVICE, O_RDWR))<0)
96 return SCI_FAILURE;
98 if (access(TOSH_PROC, R_OK)) {
99 close(fd);
100 return SCI_FAILURE;
103 regs.eax = 0xf0f0;
104 regs.ebx = 0x0000;
105 regs.ecx = 0x0000;
106 regs.edx = 0x0000;
108 if (ioctl(fd, TOSH_SMM, &regs)<0) {
109 close(fd);
110 return SCI_FAILURE;
112 close(fd);
114 *version = (int) regs.edx;
116 return (int) (regs.eax & 0xff00)>>8;
121 * Open an interface to the Toshiba hardware.
123 * Note: Set and Get will not work unless an interface has been opened.
125 int SciOpenInterface(void)
127 SMMRegisters regs;
128 int fd;
130 if ((fd=open(TOSH_DEVICE, O_RDWR ))<0)
131 return SCI_FAILURE;
133 regs.eax = 0xf1f1;
134 regs.ebx = 0x0000;
135 regs.ecx = 0x0000;
137 if (ioctl(fd, TOSH_SMM, &regs)<0) {
138 close(fd);
139 return SCI_FAILURE;
141 close(fd);
143 return (int) (regs.eax & 0xff00)>>8;
148 * Close any open interface to the hardware
150 int SciCloseInterface(void)
152 SMMRegisters regs;
153 int fd;
155 if ((fd=open(TOSH_DEVICE, O_RDWR ))<0)
156 return SCI_FAILURE;
158 regs.eax = 0xf2f2;
159 regs.ebx = 0x0000;
160 regs.ecx = 0x0000;
162 if (ioctl(fd, TOSH_SMM, &regs)<0) {
163 close(fd);
164 return SCI_FAILURE;
166 close(fd);
168 return (int) (regs.eax & 0xff00)>>8;
173 * Get the setting of a given mode of the laptop
175 int SciGet(SMMRegisters *regs)
177 int fd;
179 if ((fd=open(TOSH_DEVICE, O_RDWR ))<0)
180 return SCI_FAILURE;
182 regs->eax = 0xf3f3;
184 if (ioctl(fd, TOSH_SMM, regs)<0) {
185 close(fd);
186 return SCI_FAILURE;
188 close(fd);
190 return (int) (regs->eax & 0xff00)>>8;
195 * Set the setting of a given mode of the laptop
197 int SciSet(SMMRegisters *regs)
199 int fd;
201 if ((fd=open(TOSH_DEVICE, O_RDWR ))<0)
202 return SCI_FAILURE;
204 regs->eax = 0xf4f4;
206 if (ioctl(fd, TOSH_SMM, regs)<0) {
207 close(fd);
208 return SCI_FAILURE;
210 close(fd);
212 return (int) (regs->eax & 0xff00)>>8;
217 * Get the status of the AC Power on a Toshiba laptop.
219 int SciACPower(void)
221 SMMRegisters regs;
222 int fd;
224 if (access(TOSH_PROC, R_OK))
225 return SCI_FAILURE;
227 if ((fd=open(TOSH_DEVICE, O_RDWR))<0)
228 return SCI_FAILURE;
230 regs.eax = 0xfefe;
231 regs.ebx = 0x0003;
232 regs.ecx = 0x0000;
233 regs.edx = 0x0000;
235 if (ioctl(fd, TOSH_SMM, &regs)<0) {
236 close(fd);
237 return 0;
239 close(fd);
241 return (int) regs.ecx;