200 lines
6.9 KiB
Plaintext
200 lines
6.9 KiB
Plaintext
$OpenBSD: patch-libapm_c,v 1.2 2004/02/18 17:10:12 espie Exp $
|
|
--- libapm.c.orig 1998-06-19 02:28:23.000000000 +0200
|
|
+++ libapm.c 2004-02-18 18:03:01.000000000 +0100
|
|
@@ -17,6 +17,9 @@
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <sys/mman.h>
|
|
+#if defined(__OpenBSD__) || defined(__NetBSD__)
|
|
+#include <machine/sysarch.h>
|
|
+#endif
|
|
#include "libapm.h"
|
|
|
|
#ifndef CMOS_ACCESS
|
|
@@ -63,20 +66,20 @@ int main(int argc, char *argv[])
|
|
int r;
|
|
char c;
|
|
|
|
- struct option longopts[] = {
|
|
- { "Help", 0, 0, 'h' },
|
|
- { "Version", 0, 0, 'v' },
|
|
- { "PowerUp", 1, 0, 'P' },
|
|
- { "StandbyTime", 1, 0, 'T' },
|
|
- { "AutoOff", 1, 0, 'a' },
|
|
- { "PanelSwitch", 1, 0, 'S' },
|
|
- { "AlarmOn", 1, 0, 'A' },
|
|
- { "LcdPower", 1, 0, 'L' },
|
|
+ static struct option longopts[] = {
|
|
+ { "Help", no_argument, NULL, 'h' },
|
|
+ { "Version", no_argument, NULL, 'v' },
|
|
+ { "PowerUp", required_argument, NULL, 'P' },
|
|
+ { "StandbyTime", required_argument, NULL, 'T' },
|
|
+ { "AutoOff", required_argument, NULL, 'a' },
|
|
+ { "PanelSwitch", required_argument, NULL, 'S' },
|
|
+ { "AlarmOn", required_argument, NULL, 'A' },
|
|
+ { "LcdPower", required_argument, NULL, 'L' },
|
|
#ifndef CMOS_ACCESS
|
|
- { "Volume", 1, 0, 'V' },
|
|
- { "Off", 1, 0, 'O' },
|
|
+ { "Volume", required_argument, NULL, 'V' },
|
|
+ { "Off", required_argument, NULL, 'O' },
|
|
#endif /* CMOS_ACCESS */
|
|
- {0, 0, 0, 0}
|
|
+ {NULL, 0, NULL, 0}
|
|
};
|
|
|
|
if( 0 != geteuid() ){
|
|
@@ -101,9 +104,6 @@ int main(int argc, char *argv[])
|
|
while ((c = getopt_long(argc,argv,
|
|
"hvP:T:a:S:A:L:V:O:", longopts, NULL)) != -1) {
|
|
switch (c) {
|
|
- case 'h':
|
|
- usage();
|
|
- break;
|
|
case 'v':
|
|
printf("version : %s\n", version);
|
|
exit(0);
|
|
@@ -186,10 +186,9 @@ int main(int argc, char *argv[])
|
|
else usage();
|
|
break;
|
|
#endif /* CMOS_ACCESS */
|
|
- case '?':
|
|
+ default:
|
|
usage();
|
|
break;
|
|
- default:
|
|
}
|
|
}
|
|
#ifdef DEBUG
|
|
@@ -215,29 +214,27 @@ int main(int argc, char *argv[])
|
|
void usage(void)
|
|
{
|
|
#ifdef CMOS_ACCESS
|
|
- printf("
|
|
-usage: libapm [-v --Version]
|
|
- [-h --Help]
|
|
- [-P --PowerUp {boot,hibernation}]
|
|
- [-T --StandbyTime {0,5,10,15,30,45,60,unlimit}]
|
|
- [-a --AutoOff {disable,10,20,30,40,50,60}]
|
|
- [-S --PanelSwitch {disable,enable}]
|
|
- [-A --AlarmOn {disable,<time>}]
|
|
- [-L --LcdPower {0,1,2,3}]
|
|
- \n");
|
|
-#else
|
|
- printf("
|
|
-usage: libapm [-v --Version]
|
|
- [-h --Help]
|
|
- [-P --PowerUp {boot,hibernation}]
|
|
- [-T --StandbyTime {0,5,10,15,30,45,60,unlimit}]
|
|
- [-a --AutoOff {disable,10,20,30,40,50,60}]
|
|
- [-S --PanelSwitch {disable,enable}]
|
|
- [-A --AlarmOn {disable,<time>}]
|
|
- [-L --LcdPower {0,1,2,3}]
|
|
- [-V --Volume {0,1,2,3}]
|
|
- [-O --Off {suspend|hibernation} Use Only >= Libretto100]
|
|
- \n");
|
|
+ printf("\
|
|
+usage: libretto-config [-v --Version]\n\
|
|
+ [-h --Help]\n\
|
|
+ [-P --PowerUp {boot,hibernation}]\n\
|
|
+ [-T --StandbyTime {0,5,10,15,30,45,60,unlimit}]\n\
|
|
+ [-a --AutoOff {disable,10,20,30,40,50,60}]\n\
|
|
+ [-S --PanelSwitch {disable,enable}]\n\
|
|
+ [-A --AlarmOn {disable,<time>}]\n\
|
|
+ [-L --LcdPower {0,1,2,3}]\n");
|
|
+#else /* not CMOS_ACCESS */
|
|
+ printf("\
|
|
+usage: libretto-config [-v --Version]\n\
|
|
+ [-h --Help]\n\
|
|
+ [-P --PowerUp {boot,hibernation}]\n\
|
|
+ [-T --StandbyTime {0,5,10,15,30,45,60,unlimit}]\n\
|
|
+ [-a --AutoOff {disable,10,20,30,40,50,60}]\n\
|
|
+ [-S --PanelSwitch {disable,enable}]\n\
|
|
+ [-A --AlarmOn {disable,<time>}]\n\
|
|
+ [-L --LcdPower {0,1,2,3}]\n\
|
|
+ [-V --Volume {0,1,2,3}]\n\
|
|
+ [-O --Off {suspend|hibernation} Use Only >= Libretto100]\n");
|
|
#endif /* CMOS_ACCESS */
|
|
exit(1);
|
|
}
|
|
@@ -246,7 +243,26 @@ usage: libapm [-v --Version]
|
|
void init(void)
|
|
{
|
|
/* SMI port */
|
|
+#ifdef __linux__
|
|
ioperm(0xb2, 1, 1);
|
|
+#elif defined(__OpenBSD__) || defined(__NetBSD__)
|
|
+ u_long iomap[32];
|
|
+
|
|
+ if (i386_get_ioperm(iomap)) {
|
|
+ perror("Cannot get ioperm table");
|
|
+ exit(1);
|
|
+ }
|
|
+ /* Allow access to SMI port (0x0b2) */
|
|
+ iomap[0x0b2 / 32] &= ~(1 << (0x0b2 % 32));
|
|
+ if (i386_set_ioperm(iomap)) {
|
|
+ perror("Cannot set ioperm table");
|
|
+ exit(1);
|
|
+ }
|
|
+#elif defined(__FreeBSD__)
|
|
+ open("/dev/io", O_RDWR, 0);
|
|
+#else
|
|
+# error cannot determine I/O port access method
|
|
+#endif
|
|
}
|
|
#endif /* CMOS_ACCESS */
|
|
|
|
@@ -754,30 +770,30 @@ void print_status(void)
|
|
#endif /* CMOS_ACCESS */
|
|
|
|
#ifndef CMOS_ACCESS
|
|
- printf("
|
|
-Power Management for Libretto V%-8s
|
|
-+-----------------------------------------------------------+
|
|
-| 0) Power-up Mode : %-32s|
|
|
-| 1) Standby Time : %-32s|
|
|
-| 2) System Auto Off : %-32s|
|
|
-| 3) Panel Power On/Off : %-32s|
|
|
-| 4) Alarm Power On : %-32s|
|
|
-| 5) LCD Power : %-32s|
|
|
-| 6) Volume : %-32s|
|
|
-| 7) Off (Suspend/Hiber): %-32s|
|
|
-+-----------------------------------------------------------+\n\n",
|
|
+ printf("\n"
|
|
+"Power Management for Libretto V%-8s\n"
|
|
+"+-----------------------------------------------------------+\n"
|
|
+"| 0) Power-up Mode : %-32s|\n"
|
|
+"| 1) Standby Time : %-32s|\n"
|
|
+"| 2) System Auto Off : %-32s|\n"
|
|
+"| 3) Panel Power On/Off : %-32s|\n"
|
|
+"| 4) Alarm Power On : %-32s|\n"
|
|
+"| 5) LCD Power : %-32s|\n"
|
|
+"| 6) Volume : %-32s|\n"
|
|
+"| 7) Off (Suspend/Hiber): %-32s|\n"
|
|
+"+-----------------------------------------------------------+\n\n",
|
|
version, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7]);
|
|
#else
|
|
- printf("
|
|
-Power Management for Libretto V%-8s
|
|
-+-----------------------------------------------------------+
|
|
-| 0) Power-up Mode : %-32s|
|
|
-| 1) Standby Time : %-32s|
|
|
-| 2) System Auto Off : %-32s|
|
|
-| 3) Panel Power On/Off : %-32s|
|
|
-| 4) Alarm Power On : %-32s|
|
|
-| 5) LCD Power : %-32s|
|
|
-+-----------------------------------------------------------+\n\n",
|
|
+ printf("\n"
|
|
+"Power Management for Libretto V%-8s\n"
|
|
+"+-----------------------------------------------------------+\n"
|
|
+"| 0) Power-up Mode : %-32s|\n"
|
|
+"| 1) Standby Time : %-32s|\n"
|
|
+"| 2) System Auto Off : %-32s|\n"
|
|
+"| 3) Panel Power On/Off : %-32s|\n"
|
|
+"| 4) Alarm Power On : %-32s|\n"
|
|
+"| 5) LCD Power : %-32s|\n"
|
|
+"+-----------------------------------------------------------+\n\n",
|
|
version, s[0], s[1], s[2], s[3], s[4], s[5]);
|
|
#endif /* CMOS_ACCESS */
|
|
}
|