acpiconf.c revision 65283
1/*- 2 * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $Id: acpiconf.c,v 1.5 2000/08/08 14:12:19 iwasaki Exp $ 27 * $FreeBSD: cvs2svn/branches/ACPI4FREEBSD/usr.sbin/acpi/acpiconf/acpiconf.c 65283 2000-08-31 14:41:23Z iwasaki $ 28 */ 29 30#include <sys/param.h> 31#include <sys/acpi.h> 32 33#include <err.h> 34#include <fcntl.h> 35#include <stdio.h> 36#include <unistd.h> 37 38#define ACPIDEV "/dev/acpi" 39 40static int 41acpi_enable_disable(int enable) 42{ 43 int fd; 44 45 fd = open(ACPIDEV, O_RDWR); 46 if (fd == -1) { 47 err(1, NULL); 48 } 49 if (ioctl(fd, enable, NULL) == -1) { 50 err(1, NULL); 51 } 52 close(fd); 53 54 return (0); 55} 56 57static int 58acpi_sleep(int sleep_type) 59{ 60 int fd; 61 62 fd = open(ACPIDEV, O_RDWR); 63 if (fd == -1) { 64 err(1, NULL); 65 } 66 if (ioctl(fd, ACPIIO_SETSLPSTATE, &sleep_type) == -1) { 67 err(1, NULL); 68 } 69 close(fd); 70 71 return (0); 72} 73 74int 75main(int argc, char *argv[]) 76{ 77 char c; 78 int sleep_type; 79 80 sleep_type = -1; 81 while ((c = getopt(argc, argv, "eds:")) != -1) { 82 switch (c) { 83 case 'e': 84 acpi_enable_disable(ACPIIO_ENABLE); 85 break; 86 87 case 'd': 88 acpi_enable_disable(ACPIIO_DISABLE); 89 break; 90 91 case 's': 92 sleep_type = *optarg - '0'; 93 if (sleep_type < ACPI_S_STATE_S0 || sleep_type > ACPI_S_STATE_S5) { 94 fprintf(stderr, "%s: invalid sleep type (%d)\n", 95 argv[0], sleep_type); 96 return -1; 97 } 98 break; 99 default: 100 argc -= optind; 101 argv += optind; 102 } 103 } 104 105 if (sleep_type != -1) { 106 sleep(1); /* wait 1 sec. for key-release event */ 107 acpi_sleep(sleep_type); 108 } 109 return (0); 110} 111