2001-08-02 13:47:18 +04:00
|
|
|
/* $NetBSD: pwctl.c,v 1.7 2001/08/02 09:47:18 sato Exp $ */
|
2001-04-30 14:09:14 +04:00
|
|
|
|
|
|
|
/*-
|
2001-04-30 15:42:17 +04:00
|
|
|
* Copyright (c) 1999-2001
|
|
|
|
* TAKEMURA Shin and PocketBSD Project. All rights reserved.
|
2001-04-30 14:09:14 +04:00
|
|
|
* Copyright (c) 2000,2001
|
|
|
|
* SATO Kazumi. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the PocketBSD project
|
|
|
|
* and its contributors.
|
|
|
|
* 4. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
2001-07-31 14:37:49 +04:00
|
|
|
#include <sys/reboot.h>
|
2001-04-30 14:09:14 +04:00
|
|
|
|
2001-05-06 18:25:15 +04:00
|
|
|
#include <machine/bus.h>
|
2001-04-30 14:09:14 +04:00
|
|
|
#include <machine/config_hook.h>
|
|
|
|
#include <machine/platid.h>
|
|
|
|
#include <machine/platid_mask.h>
|
|
|
|
|
|
|
|
#include <dev/hpc/hpciovar.h>
|
|
|
|
|
|
|
|
#include "locators.h"
|
|
|
|
|
2001-08-02 13:47:18 +04:00
|
|
|
#define PWCTLDEBUG
|
|
|
|
#ifndef PWCTLDEBUG_CONF
|
|
|
|
#define PWCTLDEBUG_CONF 0
|
|
|
|
#endif
|
|
|
|
#ifdef PWCTLDEBUG
|
|
|
|
int pwctl_debug = PWCTLDEBUG_CONF;
|
2001-04-30 15:42:17 +04:00
|
|
|
#define DPRINTF(arg) if (pwctl_debug) printf arg;
|
2001-07-31 14:37:49 +04:00
|
|
|
#define VPRINTF(arg) if (bootverbose) printf arg;
|
2001-04-30 14:09:14 +04:00
|
|
|
#else
|
|
|
|
#define DPRINTF(arg)
|
2001-07-31 14:37:49 +04:00
|
|
|
#define VPRINTF(arg) if (bootverbose) printf arg;
|
2001-04-30 14:09:14 +04:00
|
|
|
#endif
|
|
|
|
|
2001-04-30 15:42:17 +04:00
|
|
|
struct pwctl_softc {
|
2001-04-30 14:09:14 +04:00
|
|
|
struct device sc_dev;
|
|
|
|
hpcio_chip_t sc_hc;
|
|
|
|
int sc_port;
|
|
|
|
long sc_id;
|
|
|
|
int sc_on, sc_off;
|
|
|
|
config_hook_tag sc_hook_tag;
|
|
|
|
config_hook_tag sc_hook_hardpower;
|
|
|
|
config_hook_tag sc_ghook_tag;
|
|
|
|
int sc_save;
|
|
|
|
int sc_initvalue;
|
|
|
|
};
|
|
|
|
|
2001-06-04 22:59:31 +04:00
|
|
|
static int pwctl_match(struct device *, struct cfdata *, void *);
|
|
|
|
static void pwctl_attach(struct device *, struct device *, void *);
|
|
|
|
static int pwctl_hook(void *, int, long, void *);
|
|
|
|
static int pwctl_ghook(void *, int, long, void *);
|
|
|
|
int pwctl_hardpower(void *, int, long, void *);
|
2001-04-30 14:09:14 +04:00
|
|
|
|
2001-04-30 15:42:17 +04:00
|
|
|
struct cfattach pwctl_ca = {
|
|
|
|
sizeof(struct pwctl_softc), pwctl_match, pwctl_attach
|
2001-04-30 14:09:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2001-06-04 22:59:31 +04:00
|
|
|
pwctl_match(struct device *parent, struct cfdata *match, void *aux)
|
2001-04-30 14:09:14 +04:00
|
|
|
{
|
2001-05-01 04:25:16 +04:00
|
|
|
struct hpcio_attach_args *haa = aux;
|
2001-04-30 14:09:14 +04:00
|
|
|
platid_mask_t mask;
|
|
|
|
|
2001-05-01 04:25:16 +04:00
|
|
|
if (strcmp(haa->haa_busname, HPCIO_BUSNAME))
|
2001-06-04 22:59:31 +04:00
|
|
|
return (0);
|
2001-04-30 14:09:14 +04:00
|
|
|
if (match->cf_loc[HPCIOIFCF_PLATFORM] == 0)
|
2001-06-04 22:59:31 +04:00
|
|
|
return (0);
|
2001-04-30 14:09:14 +04:00
|
|
|
mask = PLATID_DEREF(match->cf_loc[HPCIOIFCF_PLATFORM]);
|
|
|
|
if (!platid_match(&platid, &mask))
|
2001-06-04 22:59:31 +04:00
|
|
|
return (0);
|
|
|
|
return (1);
|
2001-04-30 14:09:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-06-04 22:59:31 +04:00
|
|
|
pwctl_attach(struct device *parent, struct device *self, void *aux)
|
2001-04-30 14:09:14 +04:00
|
|
|
{
|
|
|
|
struct hpcio_attach_args *haa = aux;
|
|
|
|
int *loc;
|
2001-04-30 15:42:17 +04:00
|
|
|
struct pwctl_softc *sc = (void*)self;
|
2001-04-30 14:09:14 +04:00
|
|
|
|
|
|
|
loc = sc->sc_dev.dv_cfdata->cf_loc;
|
2001-04-30 15:42:17 +04:00
|
|
|
sc->sc_hc = (*haa->haa_getchip)(haa->haa_sc, loc[HPCIOIFCF_IOCHIP]);
|
2001-04-30 14:09:14 +04:00
|
|
|
sc->sc_port = loc[HPCIOIFCF_PORT];
|
|
|
|
sc->sc_id = loc[HPCIOIFCF_ID];
|
|
|
|
sc->sc_on = loc[HPCIOIFCF_ACTIVE] ? 1 : 0;
|
|
|
|
sc->sc_off = loc[HPCIOIFCF_ACTIVE] ? 0 : 1;
|
|
|
|
sc->sc_initvalue = loc[HPCIOIFCF_INITVALUE];
|
2001-06-04 22:59:31 +04:00
|
|
|
|
2001-04-30 14:09:14 +04:00
|
|
|
printf(" port=%d id=%ld on=%d%s",
|
2001-06-04 22:59:31 +04:00
|
|
|
sc->sc_port, sc->sc_id, sc->sc_on,
|
|
|
|
sc->sc_initvalue == -1 ? "" :
|
|
|
|
sc->sc_initvalue ? " init=on" : " init=off");
|
2001-04-30 14:09:14 +04:00
|
|
|
|
|
|
|
if (sc->sc_port == HPCIOIFCF_PORT_DEFAULT ||
|
|
|
|
sc->sc_id == HPCIOIFCF_ID_DEFAULT) {
|
|
|
|
printf(" (ignored)");
|
|
|
|
} else {
|
|
|
|
sc->sc_hook_tag = config_hook(CONFIG_HOOK_POWERCONTROL,
|
2001-06-04 22:59:31 +04:00
|
|
|
sc->sc_id, CONFIG_HOOK_SHARE, pwctl_hook, sc);
|
2001-04-30 14:09:14 +04:00
|
|
|
sc->sc_ghook_tag = config_hook(CONFIG_HOOK_GET,
|
2001-06-04 22:59:31 +04:00
|
|
|
sc->sc_id, CONFIG_HOOK_SHARE, pwctl_ghook, sc);
|
2001-04-30 14:09:14 +04:00
|
|
|
sc->sc_hook_hardpower = config_hook(CONFIG_HOOK_PMEVENT,
|
2001-06-04 22:59:31 +04:00
|
|
|
CONFIG_HOOK_PMEVENT_HARDPOWER, CONFIG_HOOK_SHARE,
|
|
|
|
pwctl_hardpower, sc);
|
2001-04-30 14:09:14 +04:00
|
|
|
}
|
2001-06-04 22:59:31 +04:00
|
|
|
|
2001-04-30 14:09:14 +04:00
|
|
|
if (sc->sc_initvalue != -1)
|
|
|
|
hpcio_portwrite(sc->sc_hc, sc->sc_port,
|
2001-06-04 22:59:31 +04:00
|
|
|
sc->sc_initvalue ? sc->sc_on : sc->sc_off);
|
2001-04-30 14:09:14 +04:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-06-04 22:59:31 +04:00
|
|
|
pwctl_hook(void *ctx, int type, long id, void *msg)
|
2001-04-30 14:09:14 +04:00
|
|
|
{
|
2001-04-30 15:42:17 +04:00
|
|
|
struct pwctl_softc *sc = ctx;
|
2001-04-30 14:09:14 +04:00
|
|
|
|
|
|
|
DPRINTF(("pwctl hook: port %d %s(%d)", sc->sc_port,
|
2001-06-04 22:59:31 +04:00
|
|
|
msg ? "ON" : "OFF", msg ? sc->sc_on : sc->sc_off));
|
2001-04-30 14:09:14 +04:00
|
|
|
hpcio_portwrite(sc->sc_hc, sc->sc_port,
|
2001-06-04 22:59:31 +04:00
|
|
|
msg ? sc->sc_on : sc->sc_off);
|
|
|
|
|
2001-04-30 14:09:14 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-06-04 22:59:31 +04:00
|
|
|
pwctl_ghook(void *ctx, int type, long id, void *msg)
|
2001-04-30 14:09:14 +04:00
|
|
|
{
|
2001-04-30 15:42:17 +04:00
|
|
|
struct pwctl_softc *sc = ctx;
|
2001-04-30 14:09:14 +04:00
|
|
|
|
|
|
|
if (CONFIG_HOOK_VALUEP(msg))
|
2001-06-04 22:59:31 +04:00
|
|
|
return (1);
|
2001-04-30 14:09:14 +04:00
|
|
|
|
|
|
|
*(int*)msg = hpcio_portread(sc->sc_hc, sc->sc_port) == sc->sc_on;
|
|
|
|
DPRINTF(("pwctl ghook: port %d %s(%d)", sc->sc_port,
|
2001-06-04 22:59:31 +04:00
|
|
|
*(int*)msg? "ON" : "OFF", *(int*)msg ? sc->sc_on : sc->sc_off));
|
|
|
|
|
|
|
|
return (0);
|
2001-04-30 14:09:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-06-04 22:59:31 +04:00
|
|
|
pwctl_hardpower(void *ctx, int type, long id, void *msg)
|
2001-04-30 14:09:14 +04:00
|
|
|
{
|
2001-04-30 15:42:17 +04:00
|
|
|
struct pwctl_softc *sc = ctx;
|
2001-04-30 14:09:14 +04:00
|
|
|
int why =(int)msg;
|
|
|
|
|
2001-07-31 14:37:49 +04:00
|
|
|
VPRINTF(("pwctl hardpower: port %d %s: %s(%d)\n", sc->sc_port,
|
2001-06-04 22:59:31 +04:00
|
|
|
why == PWR_RESUME? "resume"
|
|
|
|
: why == PWR_SUSPEND? "suspend" : "standby",
|
|
|
|
sc->sc_save == sc->sc_on ? "on": "off", sc->sc_save));
|
2001-07-31 14:37:49 +04:00
|
|
|
|
2001-04-30 14:09:14 +04:00
|
|
|
switch (why) {
|
|
|
|
case PWR_STANDBY:
|
|
|
|
break;
|
|
|
|
case PWR_SUSPEND:
|
|
|
|
sc->sc_save = hpcio_portread(sc->sc_hc, sc->sc_port);
|
|
|
|
hpcio_portwrite(sc->sc_hc, sc->sc_port, sc->sc_off);
|
|
|
|
break;
|
|
|
|
case PWR_RESUME:
|
|
|
|
hpcio_portwrite(sc->sc_hc, sc->sc_port, sc->sc_save);
|
|
|
|
break;
|
|
|
|
}
|
2001-06-04 22:59:31 +04:00
|
|
|
|
2001-04-30 14:09:14 +04:00
|
|
|
return (0);
|
|
|
|
}
|