1*fabcfecbSjsg /* $OpenBSD: pm_direct.h,v 1.17 2024/10/22 21:50:02 jsg Exp $ */ 210b6a7dbSmpi /* $NetBSD: pm_direct.h,v 1.7 2005/01/07 04:59:58 briggs Exp $ */ 3d9a5f17fSdrahn 4d9a5f17fSdrahn /* 5d9a5f17fSdrahn * Copyright (C) 1997 Takashi Hamada 6d9a5f17fSdrahn * All rights reserved. 7d9a5f17fSdrahn * 8d9a5f17fSdrahn * Redistribution and use in source and binary forms, with or without 9d9a5f17fSdrahn * modification, are permitted provided that the following conditions 10d9a5f17fSdrahn * are met: 11d9a5f17fSdrahn * 1. Redistributions of source code must retain the above copyright 12d9a5f17fSdrahn * notice, this list of conditions and the following disclaimer. 13d9a5f17fSdrahn * 2. Redistributions in binary form must reproduce the above copyright 14d9a5f17fSdrahn * notice, this list of conditions and the following disclaimer in the 15d9a5f17fSdrahn * documentation and/or other materials provided with the distribution. 16d9a5f17fSdrahn * 3. All advertising materials mentioning features or use of this software 17d9a5f17fSdrahn * must display the following acknowledgement: 18d9a5f17fSdrahn * This product includes software developed by Takashi Hamada. 19d9a5f17fSdrahn * 4. The name of the author may not be used to endorse or promote products 20d9a5f17fSdrahn * derived from this software without specific prior written permission. 21d9a5f17fSdrahn * 22d9a5f17fSdrahn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23d9a5f17fSdrahn * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24d9a5f17fSdrahn * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25d9a5f17fSdrahn * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26d9a5f17fSdrahn * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27d9a5f17fSdrahn * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28d9a5f17fSdrahn * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29d9a5f17fSdrahn * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30d9a5f17fSdrahn * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31d9a5f17fSdrahn * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32d9a5f17fSdrahn */ 33d9a5f17fSdrahn /* From: pm_direct.h 1.0 01/02/97 Takashi Hamada */ 34d9076e62Sdrahn #ifndef _PM_DIRECT_H_ 35d9076e62Sdrahn #define _PM_DIRECT_H_ 36d9a5f17fSdrahn 37d9a5f17fSdrahn /* 38d9a5f17fSdrahn * Public declarations that other routines may need. 39d9a5f17fSdrahn */ 40d9a5f17fSdrahn 41d9a5f17fSdrahn /* data structure of the command of the Power Manager */ 42d9a5f17fSdrahn typedef struct { 43d9a5f17fSdrahn short command; /* command of the Power Manager */ 44d9a5f17fSdrahn short num_data; /* number of data */ 45d9a5f17fSdrahn char *s_buf; /* pointer to buffer for sending */ 46d9a5f17fSdrahn char *r_buf; /* pointer to buffer for receiving */ 4710b6a7dbSmpi char data[128]; /* data buffer (is it too much?) */ 4810b6a7dbSmpi /* null command seen w/ 120 data bytes */ 49d9a5f17fSdrahn } PMData; 50d9a5f17fSdrahn 51c4071fd1Smillert int pmgrop(PMData *); 52c1cc27a7Sgkoehler void pm_in_adbattach(const char *); 53146858f3Smiod int pm_adb_op(u_char *, void *, void *, int); 54c4071fd1Smillert void pm_adb_restart(void); 55c4071fd1Smillert void pm_adb_poweroff(void); 56146858f3Smiod void pm_intr(void); 57260dccbcSkettenis void pm_read_date_time(time_t *); 58260dccbcSkettenis void pm_set_date_time(time_t); 59d9076e62Sdrahn 60*fabcfecbSjsg struct pmu_battery_info { 61d9076e62Sdrahn unsigned int flags; 62d9076e62Sdrahn unsigned int cur_charge; 63d9076e62Sdrahn unsigned int max_charge; 64d9076e62Sdrahn signed int draw; 65d9076e62Sdrahn unsigned int voltage; 66d9076e62Sdrahn }; 67d9076e62Sdrahn 68c4071fd1Smillert int pm_battery_info(int, struct pmu_battery_info *); 696784ab1fStobhe int pmu_set_kbl(unsigned int); 70d9076e62Sdrahn 71c4071fd1Smillert void pm_eject_pcmcia(int); 7204c80311Sgwk void pmu_fileserver_mode(int); 73d9a5f17fSdrahn 74d9a5f17fSdrahn /* PMU commands */ 7524a1ecc6Spedro #define PMU_RESET_ADB 0x00 /* Reset ADB */ 76d9a5f17fSdrahn #define PMU_POWER_OFF 0x7e /* Turn Power off */ 77d9a5f17fSdrahn #define PMU_RESET_CPU 0xd0 /* Reset CPU */ 78d9a5f17fSdrahn 79d9a5f17fSdrahn #define PMU_SET_RTC 0x30 /* Set realtime clock */ 80d9a5f17fSdrahn #define PMU_READ_RTC 0x38 /* Read realtime clock */ 81d9a5f17fSdrahn 82d9a5f17fSdrahn #define PMU_WRITE_PRAM 0x32 /* Write PRAM */ 83d9a5f17fSdrahn #define PMU_READ_PRAM 0x3a /* Read PRAM */ 84d9a5f17fSdrahn 85d9a5f17fSdrahn #define PMU_WRITE_NVRAM 0x33 /* Write NVRAM */ 86d9a5f17fSdrahn #define PMU_READ_NVRAM 0x3b /* Read NVRAM */ 87d9a5f17fSdrahn 88d9a5f17fSdrahn #define PMU_EJECT_PCMCIA 0x4c /* Eject PCMCIA slot */ 89d9a5f17fSdrahn 90d9a5f17fSdrahn #define PMU_SET_BRIGHTNESS 0x41 /* Set backlight brightness */ 91d9a5f17fSdrahn #define PMU_READ_BRIGHTNESS 0xd9 /* Read brightness button position */ 92d9a5f17fSdrahn 93d9a5f17fSdrahn #define PMU_POWER_EVENTS 0x8f /* Send power-event commands to PMU */ 94d9a5f17fSdrahn #define PMU_SYSTEM_READY 0xdf /* tell PMU we are awake */ 95d9a5f17fSdrahn 96d9076e62Sdrahn #define PMU_SMART_BATTERY_STATE 0x6f /* Read battery state */ 97d9076e62Sdrahn 98ef0c77c0Sgkoehler #define PMU_ADB_CMD 0x20 /* Send ADB packet */ 99ef0c77c0Sgkoehler #define PMU_INT_ACK 0x78 /* Read interrupt bits */ 100d01ed945Skettenis #define PMU_I2C 0x9a /* I2C */ 101d01ed945Skettenis 102d9a5f17fSdrahn /* Bits in PMU interrupt and interrupt mask bytes */ 103d9a5f17fSdrahn #define PMU_INT_ADB_AUTO 0x04 /* ADB autopoll, when PMU_INT_ADB */ 104d9a5f17fSdrahn #define PMU_INT_PCEJECT 0x04 /* PC-card eject buttons */ 105d9a5f17fSdrahn #define PMU_INT_SNDBRT 0x08 /* sound/brightness up/down buttons */ 106d9a5f17fSdrahn #define PMU_INT_ADB 0x10 /* ADB autopoll or reply data */ 107d9a5f17fSdrahn #define PMU_INT_BATTERY 0x20 108c1cc27a7Sgkoehler #define PMU_INT_ENVIRONMENT 0x40 109d9a5f17fSdrahn #define PMU_INT_TICK 0x80 /* 1-second tick interrupt */ 11024a1ecc6Spedro #define PMU_INT_ALL 0xff /* Mask of all interrupts */ 111d9a5f17fSdrahn 112d9a5f17fSdrahn /* Bits to use with the PMU_POWER_CTRL0 command */ 113d9a5f17fSdrahn #define PMU_POW0_ON 0x80 /* OR this to power ON the device */ 114d9a5f17fSdrahn #define PMU_POW0_OFF 0x00 /* leave bit 7 to 0 to power it OFF */ 115d9a5f17fSdrahn 116d9a5f17fSdrahn /* Bits to use with the PMU_POWER_CTRL command */ 117d9a5f17fSdrahn #define PMU_POW_ON 0x80 /* OR this to power ON the device */ 118d9a5f17fSdrahn #define PMU_POW_OFF 0x00 /* leave bit 7 to 0 to power it OFF */ 119d9a5f17fSdrahn #define PMU_POW_BACKLIGHT 0x01 /* backlight power */ 120d9a5f17fSdrahn #define PMU_POW_CHARGER 0x02 /* battery charger power */ 121d9a5f17fSdrahn #define PMU_POW_IRLED 0x04 /* IR led power (on wallstreet) */ 122d9a5f17fSdrahn #define PMU_POW_MEDIABAY 0x08 /* media bay power (wallstreet/lombard ?) */ 123d9a5f17fSdrahn 124c1cc27a7Sgkoehler /* Bits from PMU_INT_ENVIRONMENT */ 125c1cc27a7Sgkoehler #define PMU_ENV_LID_CLOSED 0x01 /* The lid is closed */ 126c1cc27a7Sgkoehler #define PMU_ENV_AC_POWER 0x04 /* AC is plugged in */ 127c1cc27a7Sgkoehler #define PMU_ENV_POWER_BUTTON 0x08 /* power button on ADB-less Macs */ 128c1cc27a7Sgkoehler #define PMU_ENV_BATTERY 0x10 129c1cc27a7Sgkoehler #define PMU_ENV_OVER_TEMP 0x20 130c1cc27a7Sgkoehler 131d9a5f17fSdrahn /* PMU PMU_POWER_EVENTS commands */ 132d9a5f17fSdrahn enum { 133d9a5f17fSdrahn PMU_PWR_GET_POWERUP_EVENTS = 0x00, 134d9a5f17fSdrahn PMU_PWR_SET_POWERUP_EVENTS = 0x01, 135d9a5f17fSdrahn PMU_PWR_CLR_POWERUP_EVENTS = 0x02, 136d9a5f17fSdrahn PMU_PWR_GET_WAKEUP_EVENTS = 0x03, 137d9a5f17fSdrahn PMU_PWR_SET_WAKEUP_EVENTS = 0x04, 138d9a5f17fSdrahn PMU_PWR_CLR_WAKEUP_EVENTS = 0x05, 139d9a5f17fSdrahn }; 140d9a5f17fSdrahn 141ab4b69ddSgwk /* PMU WAKE ON EVENTS */ 142ab4b69ddSgwk 143ab4b69ddSgwk #define PMU_WAKE_KEYB 0x01 144ab4b69ddSgwk #define PMU_WAKE_AC_LOSS 0x02 145ab4b69ddSgwk #define PMU_WAKE_AC_CHG 0x04 146ab4b69ddSgwk #define PMU_WAKE_LID 0x08 147ab4b69ddSgwk #define PMU_WAKE_RING 0x10 148ab4b69ddSgwk 149d9076e62Sdrahn /* PMU Power Information */ 150d9076e62Sdrahn 151d9076e62Sdrahn #define PMU_PWR_AC_PRESENT (1 << 0) 152d9076e62Sdrahn #define PMU_PWR_BATT_PRESENT (1 << 2) 153d9076e62Sdrahn 154d01ed945Skettenis /* PMU I2C */ 155d01ed945Skettenis #define PMU_I2C_SIMPLE 0x00 156d01ed945Skettenis #define PMU_I2C_NORMAL 0x01 157d01ed945Skettenis #define PMU_I2C_COMBINED 0x02 158d01ed945Skettenis 159d9076e62Sdrahn #endif 160