Initial dockapps git repo
[dockapps.git] / wmpower-0.4.3 / src / power_management / toshiba / hci.c
blob36e58650bc20684fa72a115a57111947cd76e379
1 /* hci.c -- Hardware Configuration Interface
3 * Copyright (c) 1998-2000 Jonathan A. Buzzard (jonathan@buzzard.org.uk)
4 *
5 * $Log: hci.c,v $
6 * Revision 1.2 2003/11/06 12:48:08 noberasco
7 * Added a new machine id...
9 * Revision 1.1 2003/09/18 16:38:27 noberasco
10 * overhaul III
12 * Revision 1.1.1.1 2003/06/05 09:34:03 noberasco
13 * Initial import.
15 * Revision 1.5 2002/01/27 13:22:57 jab
16 * updated list of machine ID's
18 * Revision 1.4 2001/10/05 13:04:43 jab
19 * checked in change to using kernel module
21 * Revision 1.3 1999/12/12 11:33:39 jab
22 * changed assembler to save registers, should make the programs stabler
23 * slightly fudged addition to GetMachineID to get SCTTable ID's
25 * Revision 1.2 1999/08/15 10:43:28 jab
26 * removed the HciGet and HciSet and replaced with HciFunction
28 * Revision 1.1 1999/03/11 20:27:06 jab
29 * Initial revision
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
48 static const char rcsid[]="$Id: hci.c,v 1.2 2003/11/06 12:48:08 noberasco Exp $";
50 #include<stdio.h>
51 #include<stdlib.h>
52 #include<unistd.h>
53 #include<fcntl.h>
54 #include<sys/stat.h>
55 #include<sys/ioctl.h>
57 #include"hci.h"
60 int HciFunction(SMMRegisters *regs)
62 int fd;
64 if ((fd=open(TOSH_DEVICE, O_RDWR))<0)
65 return HCI_FAILURE;
67 if (access(TOSH_PROC, R_OK)) {
68 close(fd);
69 return HCI_FAILURE;
72 if (ioctl(fd, TOSH_SMM, regs)<0) {
73 close(fd);
74 return HCI_FAILURE;
77 close(fd);
79 return (int) (regs->eax & 0xff00)>>8;
84 * Return the BIOS version of the laptop
86 int HciGetBiosVersion(void)
88 FILE *str;
89 int major,minor;
90 char buffer[64];
92 if (access(TOSH_PROC, R_OK))
93 return -1;
95 /* open /proc/toshiba for reading */
97 if (!(str = fopen(TOSH_PROC, "r")))
98 return -1;
100 /* scan in the information */
102 fgets(buffer, sizeof(buffer)-1, str);
103 fclose(str);
104 buffer[sizeof(buffer)-1] = '\0';
105 sscanf(buffer, "%*s %*x %*d.%*d %d.%d %*x %*x\n", &major, &minor);
107 /* return the information */
109 return (major*0x100)+minor;
114 * Get the Toshiba machine identification number
116 int HciGetMachineID(int *id)
118 FILE *str;
119 char buffer[64];
121 if (access(TOSH_PROC, R_OK))
122 return HCI_FAILURE;
124 /* open /proc/toshiba for reading */
126 if (!(str = fopen(TOSH_PROC, "r")))
127 return HCI_FAILURE;
129 /* scan in the information */
131 fgets(buffer, sizeof(buffer)-1, str);
132 fclose(str);
133 buffer[sizeof(buffer)-1] = '\0';
134 sscanf(buffer, "%*s %x %*d.%*d %*d.%*d %*x %*x\n", (unsigned int *) id);
136 return HCI_SUCCESS;
141 * Return the LCD Panel type
143 int HciGetLCDPanelType(int *resolution, int *type)
145 SMMRegisters regs;
147 regs.eax = HCI_GET;
148 regs.ebx = HCI_FLAT_PANEL;
149 HciFunction(&regs);
151 *resolution = (regs.ecx & 0xff00)>>8;
152 *type = regs.ecx & 0xff;
154 return HCI_SUCCESS;