1/*	$NetBSD: pm_direct.h,v 1.11 2005/12/11 12:18:03 christos Exp $	*/
2
3/*
4 * Copyright (C) 1997 Takashi Hamada
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *  This product includes software developed by Takashi Hamada.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32/* From: pm_direct.h 1.0 01/02/97 Takashi Hamada */
33
34/*
35 * Public declarations that other routines may need.
36 */
37
38/* data structure of the command of the Power Manager */
39typedef	struct	{
40	short	command;	/* command of the Power Manager 	*/
41	short	num_data;	/* number of data			*/
42	char	*s_buf;		/* pointer to buffer for sending 	*/
43	char	*r_buf;		/* pointer to buffer for receiving	*/
44	char	data[128];	/* data buffer (is it too much?)	*/
45				/* null command seen w/ 120 data bytes  */
46}	PMData;
47
48int pmgrop(PMData *);
49int pm_intr(void *);
50void pm_init(void);
51void pm_adb_restart(void);
52void pm_adb_poweroff(void);
53void pm_read_date_time(u_long *);
54void pm_set_date_time(u_long);
55
56struct pmu_battery_info
57{
58	unsigned int flags;
59	unsigned int cur_charge;
60	unsigned int max_charge;
61	signed   int draw;
62	unsigned int voltage;
63	unsigned int secs_remaining;
64};
65
66int pm_battery_info(int, struct pmu_battery_info *);
67
68int pm_read_nvram(int);
69void pm_write_nvram(int, int);
70int pm_read_brightness(void);
71void pm_set_brightness(int);
72void pm_init_brightness(void);
73void pm_eject_pcmcia(int);
74
75/* PMU commands */
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_BATTERY_STATE	0x6b	/* Read old battery state */
97#define PMU_SMART_BATTERY_STATE	0x6f	/* Read battery state */
98
99#define PMU_ADB_CMD		0x20	/* Send ADB packet */
100#define PMU_ADB_POLL_OFF	0x21	/* Disable ADB auto-poll */
101#define PMU_SET_VOL		0x40	/* Set volume button position */
102#define PMU_GET_VOL		0x48	/* Get volume button position */
103#define PMU_SET_IMASK		0x70	/* Set interrupt mask */
104#define PMU_INT_ACK		0x78	/* Read interrupt bits */
105#define PMU_CPU_SPEED		0x7d	/* Control CPU speed on some models */
106#define PMU_SLEEP		0x7f	/* Put CPU to sleep */
107#define PMU_I2C_CMD		0x9a	/* i2c commands */
108#define PMU_GET_LID_STATE	0xdc	/* Report lid state */
109#define PMU_GET_VERSION		0xea	/* Identify thyself */
110
111/* Bits in PMU interrupt and interrupt mask bytes */
112#define PMU_INT_ADB_AUTO	0x04	/* ADB autopoll, when PMU_INT_ADB */
113#define PMU_INT_PCEJECT		0x04	/* PC-card eject buttons */
114#define PMU_INT_SNDBRT		0x08	/* sound/brightness up/down buttons */
115#define PMU_INT_ADB		0x10	/* ADB autopoll or reply data */
116#define PMU_INT_BATTERY		0x20
117#define PMU_INT_WAKEUP		0x40
118#define PMU_INT_TICK		0x80	/* 1-second tick interrupt */
119
120/* Bits to use with the PMU_POWER_CTRL0 command */
121#define PMU_POW0_ON		0x80	/* OR this to power ON the device */
122#define PMU_POW0_OFF		0x00	/* leave bit 7 to 0 to power it OFF */
123
124/* Bits to use with the PMU_POWER_CTRL command */
125#define PMU_POW_ON		0x80	/* OR this to power ON the device */
126#define PMU_POW_OFF		0x00	/* leave bit 7 to 0 to power it OFF */
127#define PMU_POW_BACKLIGHT	0x01	/* backlight power */
128#define PMU_POW_CHARGER		0x02	/* battery charger power */
129#define PMU_POW_IRLED		0x04	/* IR led power (on wallstreet) */
130#define PMU_POW_MEDIABAY	0x08	/* media bay power (wallstreet/lombard ?) */
131
132/* Bits from PMU_GET_LID_STATE or PMU_INT_ENVIRONMENT on core99 */
133#define PMU_ENV_LID_CLOSED	0x01	/* The lid is closed */
134
135/* PMU PMU_POWER_EVENTS commands */
136enum {
137	PMU_PWR_GET_POWERUP_EVENTS      = 0x00,
138	PMU_PWR_SET_POWERUP_EVENTS      = 0x01,
139	PMU_PWR_CLR_POWERUP_EVENTS      = 0x02,
140	PMU_PWR_GET_WAKEUP_EVENTS       = 0x03,
141	PMU_PWR_SET_WAKEUP_EVENTS       = 0x04,
142	PMU_PWR_CLR_WAKEUP_EVENTS       = 0x05,
143};
144
145/* PMU Power Information */
146
147#define PMU_PWR_AC_PRESENT	(1 << 0)
148#define PMU_PWR_BATT_CHARGING	(1 << 1)
149#define PMU_PWR_BATT_PRESENT	(1 << 2)
150#define PMU_PWR_PCHARGE_RESET	(1 << 6)
151
152