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