xref: /openbsd/sys/arch/macppc/dev/pm_direct.h (revision 73471bf0)
1 /*	$OpenBSD: pm_direct.h,v 1.13 2012/09/02 08:16:40 mpi 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 int	pm_adb_op(u_char *, void *, void *, int);
53 void	pm_adb_restart(void);
54 void	pm_adb_poweroff(void);
55 void	pm_intr(void);
56 void	pm_read_date_time(time_t *);
57 void	pm_set_date_time(time_t);
58 
59 struct pmu_battery_info
60 {
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 
70 void pm_eject_pcmcia(int);
71 void pmu_fileserver_mode(int);
72 
73 /* PMU commands */
74 #define PMU_RESET_ADB		0x00	/* Reset ADB */
75 #define PMU_POWER_OFF		0x7e	/* Turn Power off */
76 #define PMU_RESET_CPU		0xd0	/* Reset CPU */
77 
78 #define PMU_SET_RTC		0x30	/* Set realtime clock */
79 #define PMU_READ_RTC		0x38	/* Read realtime clock */
80 
81 #define PMU_WRITE_PRAM		0x32	/* Write PRAM */
82 #define PMU_READ_PRAM		0x3a	/* Read PRAM */
83 
84 #define PMU_WRITE_NVRAM		0x33	/* Write NVRAM */
85 #define PMU_READ_NVRAM		0x3b	/* Read NVRAM */
86 
87 #define PMU_EJECT_PCMCIA	0x4c	/* Eject PCMCIA slot */
88 
89 #define PMU_SET_BRIGHTNESS	0x41	/* Set backlight brightness */
90 #define PMU_READ_BRIGHTNESS	0xd9	/* Read brightness button position */
91 
92 #define PMU_POWER_EVENTS        0x8f    /* Send power-event commands to PMU */
93 #define PMU_SYSTEM_READY        0xdf    /* tell PMU we are awake */
94 
95 #define PMU_SMART_BATTERY_STATE	0x6f	/* Read battery state */
96 
97 #define PMU_I2C			0x9a	/* I2C */
98 
99 /* Bits in PMU interrupt and interrupt mask bytes */
100 #define PMU_INT_ADB_AUTO	0x04	/* ADB autopoll, when PMU_INT_ADB */
101 #define PMU_INT_PCEJECT		0x04	/* PC-card eject buttons */
102 #define PMU_INT_SNDBRT		0x08	/* sound/brightness up/down buttons */
103 #define PMU_INT_ADB		0x10	/* ADB autopoll or reply data */
104 #define PMU_INT_BATTERY		0x20
105 #define PMU_INT_WAKEUP		0x40
106 #define PMU_INT_TICK		0x80	/* 1-second tick interrupt */
107 #define PMU_INT_ALL		0xff	/* Mask of all interrupts */
108 
109 /* Bits to use with the PMU_POWER_CTRL0 command */
110 #define PMU_POW0_ON		0x80	/* OR this to power ON the device */
111 #define PMU_POW0_OFF		0x00	/* leave bit 7 to 0 to power it OFF */
112 
113 /* Bits to use with the PMU_POWER_CTRL command */
114 #define PMU_POW_ON		0x80	/* OR this to power ON the device */
115 #define PMU_POW_OFF		0x00	/* leave bit 7 to 0 to power it OFF */
116 #define PMU_POW_BACKLIGHT	0x01	/* backlight power */
117 #define PMU_POW_CHARGER		0x02	/* battery charger power */
118 #define PMU_POW_IRLED		0x04	/* IR led power (on wallstreet) */
119 #define PMU_POW_MEDIABAY	0x08	/* media bay power (wallstreet/lombard ?) */
120 
121 /* PMU PMU_POWER_EVENTS commands */
122 enum {
123 	PMU_PWR_GET_POWERUP_EVENTS      = 0x00,
124 	PMU_PWR_SET_POWERUP_EVENTS      = 0x01,
125 	PMU_PWR_CLR_POWERUP_EVENTS      = 0x02,
126 	PMU_PWR_GET_WAKEUP_EVENTS       = 0x03,
127 	PMU_PWR_SET_WAKEUP_EVENTS       = 0x04,
128 	PMU_PWR_CLR_WAKEUP_EVENTS       = 0x05,
129 };
130 
131 /* PMU WAKE ON EVENTS */
132 
133 #define PMU_WAKE_KEYB		0x01
134 #define PMU_WAKE_AC_LOSS	0x02
135 #define PMU_WAKE_AC_CHG		0x04
136 #define PMU_WAKE_LID		0x08
137 #define PMU_WAKE_RING		0x10
138 
139 /* PMU Power Information */
140 
141 #define PMU_PWR_AC_PRESENT	(1 << 0)
142 #define PMU_PWR_BATT_PRESENT	(1 << 2)
143 
144 /* PMU I2C */
145 #define PMU_I2C_SIMPLE		0x00
146 #define PMU_I2C_NORMAL		0x01
147 #define PMU_I2C_COMBINED	0x02
148 
149 #endif
150