xref: /netbsd-src/sys/dev/hpc/hpcapm.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /*	$NetBSD: hpcapm.c,v 1.24 2021/08/07 16:19:11 thorpej Exp $	*/
2fc3043bcSuch 
3fc3043bcSuch /*
4fc3043bcSuch  * Copyright (c) 2000 Takemura Shin
5fc3043bcSuch  * Copyright (c) 2000-2001 SATO Kazumi
6fc3043bcSuch  * All rights reserved.
7fc3043bcSuch  *
8fc3043bcSuch  * Redistribution and use in source and binary forms, with or without
9fc3043bcSuch  * modification, are permitted provided that the following conditions
10fc3043bcSuch  * are met:
11fc3043bcSuch  * 1. Redistributions of source code must retain the above copyright
12fc3043bcSuch  *    notice, this list of conditions and the following disclaimer.
13fc3043bcSuch  * 2. Redistributions in binary form must reproduce the above copyright
14fc3043bcSuch  *    notice, this list of conditions and the following disclaimer in the
15fc3043bcSuch  *    documentation and/or other materials provided with the distribution.
16fc3043bcSuch  *
17fc3043bcSuch  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18fc3043bcSuch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19fc3043bcSuch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20fc3043bcSuch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21fc3043bcSuch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22fc3043bcSuch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23fc3043bcSuch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24fc3043bcSuch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25fc3043bcSuch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26fc3043bcSuch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27fc3043bcSuch  * SUCH DAMAGE.
28fc3043bcSuch  *
29fc3043bcSuch  */
30fc3043bcSuch 
31fc3043bcSuch #include <sys/cdefs.h>
32*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: hpcapm.c,v 1.24 2021/08/07 16:19:11 thorpej Exp $");
339eddf385Speter 
349eddf385Speter #ifdef _KERNEL_OPT
359eddf385Speter #include "opt_hpcapm.h"
369eddf385Speter #endif
37fc3043bcSuch 
38fc3043bcSuch #include <sys/param.h>
39fc3043bcSuch #include <sys/device.h>
40fc3043bcSuch #include <sys/kernel.h>
41fc3043bcSuch #include <sys/systm.h>
429a25b0cbSuwe #include <sys/selinfo.h> /* XXX: for apm_softc that is exposed here */
43fc3043bcSuch 
44fc3043bcSuch #include <dev/hpc/apm/apmvar.h>
45fc3043bcSuch 
46a2a38285Sad #include <sys/bus.h>
47fc3043bcSuch #include <machine/config_hook.h>
48fc3043bcSuch #include <machine/platid.h>
49fc3043bcSuch #include <machine/platid_mask.h>
50fc3043bcSuch 
5182b8cabaSriastradh #include "ioconf.h"
5282b8cabaSriastradh 
53fc3043bcSuch #ifdef HPCAPMDEBUG
54fc3043bcSuch #ifndef HPCAPMDEBUG_CONF
55fc3043bcSuch #define HPCAPMDEBUG_CONF 1
56fc3043bcSuch #endif
57fc3043bcSuch int	hpcapm_debug = HPCAPMDEBUG_CONF;
58fc3043bcSuch #define	DPRINTF(arg)     do { if (hpcapm_debug) printf arg; } while(0);
59fc3043bcSuch #define	DPRINTFN(n, arg) do { if (hpcapm_debug > (n)) printf arg; } while (0);
60fc3043bcSuch #else
61fc3043bcSuch #define	DPRINTF(arg)     do { } while (0);
62fc3043bcSuch #define DPRINTFN(n, arg) do { } while (0);
63fc3043bcSuch #endif
64fc3043bcSuch 
65fc3043bcSuch /* Definition of the driver for autoconfig. */
66529e91fcScegger static int	hpcapm_match(device_t, cfdata_t, void *);
67529e91fcScegger static void	hpcapm_attach(device_t, device_t, void *);
68fc3043bcSuch static int	hpcapm_hook(void *, int, long, void *);
69fc3043bcSuch 
70fc3043bcSuch static void	hpcapm_disconnect(void *);
71fc3043bcSuch static void	hpcapm_enable(void *, int);
72fc3043bcSuch static int	hpcapm_set_powstate(void *, u_int, u_int);
739a25b0cbSuwe static int	hpcapm_get_powstat(void *, u_int, struct apm_power_info *);
74fc3043bcSuch static int	hpcapm_get_event(void *, u_int *, u_int *);
75fc3043bcSuch static void	hpcapm_cpu_busy(void *);
76fc3043bcSuch static void	hpcapm_cpu_idle(void *);
77fc3043bcSuch static void	hpcapm_get_capabilities(void *, u_int *, u_int *);
78fc3043bcSuch 
79fc3043bcSuch struct apmhpc_softc {
80fc3043bcSuch 	void *sc_apmdev;
81fc3043bcSuch 	volatile unsigned int events;
82fc3043bcSuch 	volatile int power_state;
83e4d63225Suwe 	volatile int battery_flags;
84fc3043bcSuch 	volatile int ac_state;
85fc3043bcSuch 	config_hook_tag	sc_standby_hook;
86fc3043bcSuch 	config_hook_tag	sc_suspend_hook;
87fc3043bcSuch 	config_hook_tag sc_battery_hook;
88fc3043bcSuch 	config_hook_tag sc_ac_hook;
89fc3043bcSuch 	int battery_life;
90fc3043bcSuch 	int minutes_left;
91fc3043bcSuch };
92fc3043bcSuch 
93cbab9cadSchs CFATTACH_DECL_NEW(hpcapm, sizeof (struct apmhpc_softc),
94fc3043bcSuch     hpcapm_match, hpcapm_attach, NULL, NULL);
95fc3043bcSuch 
96fc3043bcSuch struct apm_accessops hpcapm_accessops = {
97fc3043bcSuch 	hpcapm_disconnect,
98fc3043bcSuch 	hpcapm_enable,
99fc3043bcSuch 	hpcapm_set_powstate,
100fc3043bcSuch 	hpcapm_get_powstat,
101fc3043bcSuch 	hpcapm_get_event,
102fc3043bcSuch 	hpcapm_cpu_busy,
103fc3043bcSuch 	hpcapm_cpu_idle,
104fc3043bcSuch 	hpcapm_get_capabilities,
105fc3043bcSuch };
106fc3043bcSuch 
107fc3043bcSuch static int
hpcapm_match(device_t parent,cfdata_t cf,void * aux)108cbab9cadSchs hpcapm_match(device_t parent, cfdata_t cf, void *aux)
109fc3043bcSuch {
11044b35078Suwe 
1113ca5c268Scube 	return 1;
112fc3043bcSuch }
113fc3043bcSuch 
114fc3043bcSuch static void
hpcapm_attach(device_t parent,device_t self,void * aux)115cbab9cadSchs hpcapm_attach(device_t parent, device_t self, void *aux)
116fc3043bcSuch {
117fc3043bcSuch 	struct apmhpc_softc *sc;
118fc3043bcSuch 	struct apmdev_attach_args aaa;
119fc3043bcSuch 
12092c7bba3Sthorpej 	sc = device_private(self);
121fc3043bcSuch 	printf(": pseudo power management module\n");
122fc3043bcSuch 
123fc3043bcSuch 	sc->events = 0;
124fc3043bcSuch 	sc->power_state = APM_SYS_READY;
125e4d63225Suwe 	sc->battery_flags = APM_BATT_FLAG_UNKNOWN;
126fc3043bcSuch 	sc->ac_state = APM_AC_UNKNOWN;
127fc3043bcSuch 	sc->battery_life = APM_BATT_LIFE_UNKNOWN;
128fc3043bcSuch 	sc->minutes_left = 0;
129fc3043bcSuch 	sc->sc_standby_hook = config_hook(CONFIG_HOOK_PMEVENT,
130fc3043bcSuch 					  CONFIG_HOOK_PMEVENT_STANDBYREQ,
131fc3043bcSuch 					  CONFIG_HOOK_EXCLUSIVE,
132fc3043bcSuch 					  hpcapm_hook, sc);
133fc3043bcSuch 	sc->sc_suspend_hook = config_hook(CONFIG_HOOK_PMEVENT,
134fc3043bcSuch 					  CONFIG_HOOK_PMEVENT_SUSPENDREQ,
135fc3043bcSuch 					  CONFIG_HOOK_EXCLUSIVE,
136fc3043bcSuch 					  hpcapm_hook, sc);
137fc3043bcSuch 
138fc3043bcSuch 	sc->sc_battery_hook = config_hook(CONFIG_HOOK_PMEVENT,
139fc3043bcSuch 					  CONFIG_HOOK_PMEVENT_BATTERY,
140fc3043bcSuch 					  CONFIG_HOOK_SHARE,
141fc3043bcSuch 					  hpcapm_hook, sc);
142fc3043bcSuch 
143b320dcd1Suwe 	sc->sc_ac_hook = config_hook(CONFIG_HOOK_PMEVENT,
144fc3043bcSuch 				     CONFIG_HOOK_PMEVENT_AC,
145fc3043bcSuch 				     CONFIG_HOOK_SHARE,
146fc3043bcSuch 				     hpcapm_hook, sc);
147fc3043bcSuch 
148fc3043bcSuch 	aaa.accessops = &hpcapm_accessops;
149fc3043bcSuch 	aaa.accesscookie = sc;
150fc3043bcSuch 	aaa.apm_detail = 0x0102;
151fc3043bcSuch 
152*c7fb772bSthorpej 	sc->sc_apmdev = config_found(self, &aaa, apmprint, CFARGS_NONE);
1532ec6410aSuwe 
1542ec6410aSuwe 	if (!pmf_device_register(self, NULL, NULL))
1552ec6410aSuwe 		aprint_error_dev(self, "unable to establish power handler\n");
156fc3043bcSuch }
157fc3043bcSuch 
158fc3043bcSuch static int
hpcapm_hook(void * ctx,int type,long id,void * msg)159fc3043bcSuch hpcapm_hook(void *ctx, int type, long id, void *msg)
160fc3043bcSuch {
161fc3043bcSuch 	struct apmhpc_softc *sc;
162fc3043bcSuch 	int s;
163fc3043bcSuch 	int charge;
164fc3043bcSuch 	int message;
165fc3043bcSuch 
166fc3043bcSuch 	sc = ctx;
167fc3043bcSuch 
168fc3043bcSuch 	if (type != CONFIG_HOOK_PMEVENT)
169fc3043bcSuch 		return 1;
170fc3043bcSuch 
171fc3043bcSuch 	if (CONFIG_HOOK_VALUEP(msg))
172fc3043bcSuch 		message = (int)msg;
173fc3043bcSuch 	else
174fc3043bcSuch 		message = *(int *)msg;
175fc3043bcSuch 
176fc3043bcSuch 	s = splhigh();
177fc3043bcSuch 	switch (id) {
178fc3043bcSuch 	case CONFIG_HOOK_PMEVENT_STANDBYREQ:
179fc3043bcSuch 		if (sc->power_state != APM_SYS_STANDBY) {
180fc3043bcSuch 			sc->events |= (1 << APM_USER_STANDBY_REQ);
181fc3043bcSuch 		} else {
182fc3043bcSuch 			sc->events |= (1 << APM_NORMAL_RESUME);
183fc3043bcSuch 		}
184fc3043bcSuch 		break;
185fc3043bcSuch 	case CONFIG_HOOK_PMEVENT_SUSPENDREQ:
186fc3043bcSuch 		if (sc->power_state != APM_SYS_SUSPEND) {
187223213b9Speter 			DPRINTF(("hpcapm: suspend request\n"));
188fc3043bcSuch 			sc->events |= (1 << APM_USER_SUSPEND_REQ);
189fc3043bcSuch 		} else {
190fc3043bcSuch 			sc->events |= (1 << APM_NORMAL_RESUME);
191fc3043bcSuch 		}
192fc3043bcSuch 		break;
193fc3043bcSuch 	case CONFIG_HOOK_PMEVENT_BATTERY:
194fc3043bcSuch 		switch (message) {
195fc3043bcSuch 		case CONFIG_HOOK_BATT_CRITICAL:
196fc3043bcSuch 			DPRINTF(("hpcapm: battery state critical\n"));
197e4d63225Suwe 			charge = sc->battery_flags & APM_BATT_FLAG_CHARGING;
198e4d63225Suwe 			sc->battery_flags = APM_BATT_FLAG_CRITICAL;
199e4d63225Suwe 			sc->battery_flags |= charge;
200fc3043bcSuch 			sc->battery_life = 0;
201fc3043bcSuch 			break;
202fc3043bcSuch 		case CONFIG_HOOK_BATT_LOW:
203fc3043bcSuch 			DPRINTF(("hpcapm: battery state low\n"));
204e4d63225Suwe 			charge = sc->battery_flags & APM_BATT_FLAG_CHARGING;
205e4d63225Suwe 			sc->battery_flags = APM_BATT_FLAG_LOW;
206e4d63225Suwe 			sc->battery_flags |= charge;
207fc3043bcSuch 			break;
208fc3043bcSuch 		case CONFIG_HOOK_BATT_HIGH:
209fc3043bcSuch 			DPRINTF(("hpcapm: battery state high\n"));
210e4d63225Suwe 			charge = sc->battery_flags & APM_BATT_FLAG_CHARGING;
211e4d63225Suwe 			sc->battery_flags = APM_BATT_FLAG_HIGH;
212e4d63225Suwe 			sc->battery_flags |= charge;
213fc3043bcSuch 			break;
214fc3043bcSuch 		case CONFIG_HOOK_BATT_10P:
215fc3043bcSuch 			DPRINTF(("hpcapm: battery life 10%%\n"));
216fc3043bcSuch 			sc->battery_life = 10;
217fc3043bcSuch 			break;
218fc3043bcSuch 		case CONFIG_HOOK_BATT_20P:
219fc3043bcSuch 			DPRINTF(("hpcapm: battery life 20%%\n"));
220fc3043bcSuch 			sc->battery_life = 20;
221fc3043bcSuch 			break;
222fc3043bcSuch 		case CONFIG_HOOK_BATT_30P:
223fc3043bcSuch 			DPRINTF(("hpcapm: battery life 30%%\n"));
224fc3043bcSuch 			sc->battery_life = 30;
225fc3043bcSuch 			break;
226fc3043bcSuch 		case CONFIG_HOOK_BATT_40P:
227fc3043bcSuch 			DPRINTF(("hpcapm: battery life 40%%\n"));
228fc3043bcSuch 			sc->battery_life = 40;
229fc3043bcSuch 			break;
230fc3043bcSuch 		case CONFIG_HOOK_BATT_50P:
231fc3043bcSuch 			DPRINTF(("hpcapm: battery life 50%%\n"));
232fc3043bcSuch 			sc->battery_life = 50;
233fc3043bcSuch 			break;
234fc3043bcSuch 		case CONFIG_HOOK_BATT_60P:
235fc3043bcSuch 			DPRINTF(("hpcapm: battery life 60%%\n"));
236fc3043bcSuch 			sc->battery_life = 60;
237fc3043bcSuch 			break;
238fc3043bcSuch 		case CONFIG_HOOK_BATT_70P:
239fc3043bcSuch 			DPRINTF(("hpcapm: battery life 70%%\n"));
240fc3043bcSuch 			sc->battery_life = 70;
241fc3043bcSuch 			break;
242fc3043bcSuch 		case CONFIG_HOOK_BATT_80P:
243fc3043bcSuch 			DPRINTF(("hpcapm: battery life 80%%\n"));
244fc3043bcSuch 			sc->battery_life = 80;
245fc3043bcSuch 			break;
246fc3043bcSuch 		case CONFIG_HOOK_BATT_90P:
247fc3043bcSuch 			DPRINTF(("hpcapm: battery life 90%%\n"));
248fc3043bcSuch 			sc->battery_life = 90;
249fc3043bcSuch 			break;
250fc3043bcSuch 		case CONFIG_HOOK_BATT_100P:
251fc3043bcSuch 			DPRINTF(("hpcapm: battery life 100%%\n"));
252fc3043bcSuch 			sc->battery_life = 100;
253fc3043bcSuch 			break;
254fc3043bcSuch 		case CONFIG_HOOK_BATT_UNKNOWN:
255fc3043bcSuch 			DPRINTF(("hpcapm: battery state unknown\n"));
256e4d63225Suwe 			sc->battery_flags = APM_BATT_FLAG_UNKNOWN;
257fc3043bcSuch 			sc->battery_life = APM_BATT_LIFE_UNKNOWN;
258fc3043bcSuch 			break;
259fc3043bcSuch 		case CONFIG_HOOK_BATT_NO_SYSTEM_BATTERY:
260fc3043bcSuch 			DPRINTF(("hpcapm: battery state no system battery?\n"));
261e4d63225Suwe 			sc->battery_flags = APM_BATT_FLAG_NO_SYSTEM_BATTERY;
262fc3043bcSuch 			sc->battery_life = APM_BATT_LIFE_UNKNOWN;
263fc3043bcSuch 			break;
264fc3043bcSuch 		}
265fc3043bcSuch 		break;
266fc3043bcSuch 	case CONFIG_HOOK_PMEVENT_AC:
267fc3043bcSuch 		switch (message) {
268fc3043bcSuch 		case CONFIG_HOOK_AC_OFF:
269223213b9Speter 			DPRINTF(("hpcapm: ac not connected\n"));
270e4d63225Suwe 			sc->battery_flags &= ~APM_BATT_FLAG_CHARGING;
271fc3043bcSuch 			sc->ac_state = APM_AC_OFF;
272fc3043bcSuch 			break;
273fc3043bcSuch 		case CONFIG_HOOK_AC_ON_CHARGE:
274fc3043bcSuch 			DPRINTF(("hpcapm: charging\n"));
275e4d63225Suwe 			sc->battery_flags |= APM_BATT_FLAG_CHARGING;
276fc3043bcSuch 			sc->ac_state = APM_AC_ON;
277fc3043bcSuch 			break;
278fc3043bcSuch 		case CONFIG_HOOK_AC_ON_NOCHARGE:
279223213b9Speter 			DPRINTF(("hpcapm: ac connected\n"));
280e4d63225Suwe 			sc->battery_flags &= ~APM_BATT_FLAG_CHARGING;
281fc3043bcSuch 			sc->ac_state = APM_AC_ON;
282fc3043bcSuch 			break;
283fc3043bcSuch 		case CONFIG_HOOK_AC_UNKNOWN:
284fc3043bcSuch 			sc->ac_state = APM_AC_UNKNOWN;
285fc3043bcSuch 			break;
286fc3043bcSuch 		}
287fc3043bcSuch 		break;
288fc3043bcSuch 	}
289fc3043bcSuch 	splx(s);
290fc3043bcSuch 
291fc3043bcSuch 	return (0);
292fc3043bcSuch }
293fc3043bcSuch 
294fc3043bcSuch static void
hpcapm_disconnect(void * scx)295fc3043bcSuch hpcapm_disconnect(void *scx)
296fc3043bcSuch {
297fc3043bcSuch }
298fc3043bcSuch 
299fc3043bcSuch static void
hpcapm_enable(void * scx,int onoff)300168cd830Schristos hpcapm_enable(void *scx, int onoff)
301fc3043bcSuch {
302fc3043bcSuch }
303fc3043bcSuch 
304fc3043bcSuch static int
hpcapm_set_powstate(void * scx,u_int devid,u_int powstat)305fc3043bcSuch hpcapm_set_powstate(void *scx, u_int devid, u_int powstat)
306fc3043bcSuch {
307fc3043bcSuch 	struct apmhpc_softc *sc;
308fc3043bcSuch 	int s;
309fc3043bcSuch 
310fc3043bcSuch 	sc = scx;
311fc3043bcSuch 
312fc3043bcSuch 	if (devid != APM_DEV_ALLDEVS)
313fc3043bcSuch 		return APM_ERR_UNRECOG_DEV;
314fc3043bcSuch 
315fc3043bcSuch 	switch (powstat) {
316fc3043bcSuch 	case APM_SYS_READY:
317fc3043bcSuch 		DPRINTF(("hpcapm: set power state READY\n"));
318fc3043bcSuch 		sc->power_state = APM_SYS_READY;
319fc3043bcSuch 		break;
320fc3043bcSuch 	case APM_SYS_STANDBY:
321fc3043bcSuch 		DPRINTF(("hpcapm: set power state STANDBY\n"));
322fc3043bcSuch 		s = splhigh();
323fc3043bcSuch 		config_hook_call(CONFIG_HOOK_PMEVENT,
324fc3043bcSuch 				 CONFIG_HOOK_PMEVENT_HARDPOWER,
325fc3043bcSuch 				 (void *)PWR_STANDBY);
326fc3043bcSuch 		sc->power_state = APM_SYS_STANDBY;
327fc3043bcSuch 		machine_standby();
328fc3043bcSuch 		config_hook_call_reverse(CONFIG_HOOK_PMEVENT,
329fc3043bcSuch 		    CONFIG_HOOK_PMEVENT_HARDPOWER,
330fc3043bcSuch 		    (void *)PWR_RESUME);
331fc3043bcSuch 		DPRINTF(("hpcapm: resume\n"));
332fc3043bcSuch 		splx(s);
333fc3043bcSuch 		break;
334fc3043bcSuch 	case APM_SYS_SUSPEND:
335fc3043bcSuch 		DPRINTF(("hpcapm: set power state SUSPEND...\n"));
336fc3043bcSuch 		s = splhigh();
337fc3043bcSuch 		config_hook_call(CONFIG_HOOK_PMEVENT,
338fc3043bcSuch 		    CONFIG_HOOK_PMEVENT_HARDPOWER,
339fc3043bcSuch 		    (void *)PWR_SUSPEND);
340fc3043bcSuch 		sc->power_state = APM_SYS_SUSPEND;
341fc3043bcSuch 		machine_sleep();
342fc3043bcSuch 		config_hook_call_reverse(CONFIG_HOOK_PMEVENT,
343fc3043bcSuch 				 CONFIG_HOOK_PMEVENT_HARDPOWER,
344fc3043bcSuch 				 (void *)PWR_RESUME);
345fc3043bcSuch 		DPRINTF(("hpcapm: resume\n"));
346fc3043bcSuch 		splx(s);
347fc3043bcSuch 		break;
348fc3043bcSuch 	case APM_SYS_OFF:
349fc3043bcSuch 		DPRINTF(("hpcapm: set power state OFF\n"));
350fc3043bcSuch 		sc->power_state = APM_SYS_OFF;
351fc3043bcSuch 		break;
352fc3043bcSuch 	case APM_LASTREQ_INPROG:
353fc3043bcSuch 		/*DPRINTF(("hpcapm: set power state INPROG\n"));
354fc3043bcSuch 		 */
355fc3043bcSuch 		break;
356fc3043bcSuch 	case APM_LASTREQ_REJECTED:
357fc3043bcSuch 		DPRINTF(("hpcapm: set power state REJECTED\n"));
358fc3043bcSuch 		break;
359fc3043bcSuch 	}
360fc3043bcSuch 
361fc3043bcSuch 	return (0);
362fc3043bcSuch }
363fc3043bcSuch 
364fc3043bcSuch static int
hpcapm_get_powstat(void * scx,u_int batteryid,struct apm_power_info * pinfo)3659a25b0cbSuwe hpcapm_get_powstat(void *scx, u_int batteryid, struct apm_power_info *pinfo)
366fc3043bcSuch {
367fc3043bcSuch 	struct apmhpc_softc *sc;
368588f33c3Snakayama 	int val;
369fc3043bcSuch 
370fc3043bcSuch 	sc = scx;
371fc3043bcSuch 
372e4d63225Suwe 	pinfo->nbattery = 0;
373e4d63225Suwe 	pinfo->batteryid = 0;
374e4d63225Suwe 	pinfo->minutes_valid = 0;
375e4d63225Suwe 	pinfo->minutes_left = 0;
376e4d63225Suwe 	pinfo->battery_state = APM_BATT_UNKNOWN; /* XXX: ignored */
377e4d63225Suwe 
378588f33c3Snakayama 	if (config_hook_call(CONFIG_HOOK_GET,
379588f33c3Snakayama 			     CONFIG_HOOK_ACADAPTER, &val) != -1)
380588f33c3Snakayama 		pinfo->ac_state = val;
381588f33c3Snakayama 	else
382fc3043bcSuch 		pinfo->ac_state = sc->ac_state;
383e4d63225Suwe 
384588f33c3Snakayama 	if (config_hook_call(CONFIG_HOOK_GET,
385588f33c3Snakayama 			     CONFIG_HOOK_CHARGE, &val) != -1)
386e4d63225Suwe 		pinfo->battery_flags = val;
387588f33c3Snakayama 	else
388e4d63225Suwe 		pinfo->battery_flags = sc->battery_flags;
389e4d63225Suwe 
390588f33c3Snakayama 	if (config_hook_call(CONFIG_HOOK_GET,
391588f33c3Snakayama 			     CONFIG_HOOK_BATTERYVAL, &val) != -1)
392588f33c3Snakayama 		pinfo->battery_life = val;
393588f33c3Snakayama 	else
394fc3043bcSuch 		pinfo->battery_life = sc->battery_life;
395e4d63225Suwe 
396fc3043bcSuch 	return (0);
397fc3043bcSuch }
398fc3043bcSuch 
399fc3043bcSuch static int
hpcapm_get_event(void * scx,u_int * event_type,u_int * event_info)400fc3043bcSuch hpcapm_get_event(void *scx, u_int *event_type, u_int *event_info)
401fc3043bcSuch {
402fc3043bcSuch 	struct apmhpc_softc *sc;
403fc3043bcSuch 	int s, i;
404fc3043bcSuch 
405fc3043bcSuch 	sc = scx;
406fc3043bcSuch 	s = splhigh();
407fc3043bcSuch 	for (i = APM_STANDBY_REQ; i <= APM_CAP_CHANGE; i++) {
408fc3043bcSuch 		if (sc->events & (1 << i)) {
409fc3043bcSuch 			sc->events &= ~(1 << i);
410fc3043bcSuch 			*event_type = i;
411fc3043bcSuch 			if (*event_type == APM_NORMAL_RESUME ||
412fc3043bcSuch 			    *event_type == APM_CRIT_RESUME) {
413fc3043bcSuch 				/* pccard power off in the suspend state */
414fc3043bcSuch 				*event_info = 1;
415fc3043bcSuch 				sc->power_state = APM_SYS_READY;
416fc3043bcSuch 			} else
417fc3043bcSuch 				*event_info = 0;
4185a2b751dSmaxv 			splx(s);
4195a2b751dSmaxv 
420fc3043bcSuch 			return (0);
421fc3043bcSuch 		}
422fc3043bcSuch 	}
423fc3043bcSuch 	splx(s);
424fc3043bcSuch 
425fc3043bcSuch 	return APM_ERR_NOEVENTS;
426fc3043bcSuch }
427fc3043bcSuch 
428fc3043bcSuch static void
hpcapm_cpu_busy(void * scx)429fc3043bcSuch hpcapm_cpu_busy(void *scx)
430fc3043bcSuch {
431fc3043bcSuch }
432fc3043bcSuch 
433fc3043bcSuch static void
hpcapm_cpu_idle(void * scx)434fc3043bcSuch hpcapm_cpu_idle(void *scx)
435fc3043bcSuch {
436fc3043bcSuch }
437fc3043bcSuch 
438fc3043bcSuch static void
hpcapm_get_capabilities(void * scx,u_int * numbatts,u_int * capflags)439fc3043bcSuch hpcapm_get_capabilities(void *scx, u_int *numbatts, u_int *capflags)
440fc3043bcSuch {
441fc3043bcSuch 	*numbatts = 0;
442fc3043bcSuch 	*capflags = APM_GLOBAL_STANDBY | APM_GLOBAL_SUSPEND;
443fc3043bcSuch }
444