convert to pmf

This commit is contained in:
christos 2010-01-02 01:42:49 +00:00
parent 5fc5137232
commit 641f5484f1
3 changed files with 112 additions and 115 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ym.c,v 1.35 2008/04/28 20:23:52 martin Exp $ */ /* $NetBSD: ym.c,v 1.36 2010/01/02 01:42:49 christos Exp $ */
/*- /*-
* Copyright (c) 1999-2002 The NetBSD Foundation, Inc. * Copyright (c) 1999-2002 The NetBSD Foundation, Inc.
@ -60,7 +60,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ym.c,v 1.35 2008/04/28 20:23:52 martin Exp $"); __KERNEL_RCSID(0, "$NetBSD: ym.c,v 1.36 2010/01/02 01:42:49 christos Exp $");
#include "mpu_ym.h" #include "mpu_ym.h"
#include "opt_ym.h" #include "opt_ym.h"
@ -148,7 +148,6 @@ int ym_intr(void *);
#ifndef AUDIO_NO_POWER_CTL #ifndef AUDIO_NO_POWER_CTL
static void ym_save_codec_regs(struct ym_softc *); static void ym_save_codec_regs(struct ym_softc *);
static void ym_restore_codec_regs(struct ym_softc *); static void ym_restore_codec_regs(struct ym_softc *);
void ym_power_hook(int, void *);
int ym_codec_power_ctl(void *, int); int ym_codec_power_ctl(void *, int);
static void ym_chip_powerdown(struct ym_softc *); static void ym_chip_powerdown(struct ym_softc *);
static void ym_chip_powerup(struct ym_softc *, int); static void ym_chip_powerup(struct ym_softc *, int);
@ -163,6 +162,8 @@ static void ym_hvol_to_master_gain(struct ym_softc *);
static void ym_set_mic_gain(struct ym_softc *, int); static void ym_set_mic_gain(struct ym_softc *, int);
static void ym_set_3d(struct ym_softc *, mixer_ctrl_t *, static void ym_set_3d(struct ym_softc *, mixer_ctrl_t *,
struct ad1848_volume *, int); struct ad1848_volume *, int);
static bool ym_suspend(device_t PMF_FN_PROTO);
static bool ym_resume(device_t PMF_FN_PROTO);
const struct audio_hw_if ym_hw_if = { const struct audio_hw_if ym_hw_if = {
@ -296,7 +297,10 @@ ym_attach(struct ym_softc *sc)
#endif #endif
ym_powerdown_blocks(sc); ym_powerdown_blocks(sc);
powerhook_establish(DVNAME(sc), ym_power_hook, sc); if (!pmf_device_register(&ac->sc_dev, ym_suspend, ym_resume)) {
aprint_error_dev(&ac->sc_dev,
"cannot set power mgmt handler\n");
}
#endif #endif
/* Set tone control to the default position. */ /* Set tone control to the default position. */
@ -1102,76 +1106,79 @@ ym_restore_codec_regs(struct ym_softc *sc)
* Currently only the parameters, such as output gain, are restored. * Currently only the parameters, such as output gain, are restored.
* DMA state should also be restored. FIXME. * DMA state should also be restored. FIXME.
*/ */
void static bool
ym_power_hook(int why, void *v) ym_suspend(device_t self PMF_FN_ARGS)
{ {
struct ym_softc *sc; struct ym_softc *sc = device_private(self);
int i, xmax; int i, xmax;
int s; int s;
sc = v; sc = v;
DPRINTF(("%s: ym_power_hook: why = %d\n", DVNAME(sc), why)); DPRINTF(("%s: ym_power_hook: suspend\n", DVNAME(sc)));
s = splaudio(); s = splaudio();
switch (why) { /*
case PWR_SUSPEND: * suspending...
case PWR_STANDBY: */
/* callout_stop(&sc->sc_powerdown_ch);
* suspending... if (sc->sc_turning_off)
*/ ym_powerdown_blocks(sc);
callout_stop(&sc->sc_powerdown_ch);
if (sc->sc_turning_off)
ym_powerdown_blocks(sc);
/* /*
* Save CODEC registers. * Save CODEC registers.
* Note that the registers read incorrect * Note that the registers read incorrect
* if the CODEC part is in power-down mode. * if the CODEC part is in power-down mode.
*/ */
if (sc->sc_on_blocks & YM_POWER_CODEC_DIGITAL) if (sc->sc_on_blocks & YM_POWER_CODEC_DIGITAL)
ym_save_codec_regs(sc); ym_save_codec_regs(sc);
/* /*
* Save OPL3-SA3 control registers and power-down the chip. * Save OPL3-SA3 control registers and power-down the chip.
* Note that the registers read incorrect * Note that the registers read incorrect
* if the chip is in global power-down mode. * if the chip is in global power-down mode.
*/ */
sc->sc_sa3_scan[SA3_PWR_MNG] = ym_read(sc, SA3_PWR_MNG); sc->sc_sa3_scan[SA3_PWR_MNG] = ym_read(sc, SA3_PWR_MNG);
if (sc->sc_on_blocks) if (sc->sc_on_blocks)
ym_chip_powerdown(sc); ym_chip_powerdown(sc);
break;
case PWR_RESUME:
/*
* resuming...
*/
ym_chip_powerup(sc, 1);
ym_init(sc); /* power-on CODEC */
/* Restore control registers. */
xmax = YM_IS_SA3(sc)? YM_SAVE_REG_MAX_SA3 : YM_SAVE_REG_MAX_SA2;
for (i = SA3_PWR_MNG + 1; i <= xmax; i++) {
if (i == SA3_SB_SCAN || i == SA3_SB_SCAN_DATA ||
i == SA3_DPWRDWN)
continue;
ym_write(sc, i, sc->sc_sa3_scan[i]);
}
/* Restore CODEC registers (including mixer). */
ym_restore_codec_regs(sc);
/* Restore global/digital power-down state. */
ym_write(sc, SA3_PWR_MNG, sc->sc_sa3_scan[SA3_PWR_MNG]);
if (YM_IS_SA3(sc))
ym_write(sc, SA3_DPWRDWN, sc->sc_sa3_scan[SA3_DPWRDWN]);
break;
case PWR_SOFTSUSPEND:
case PWR_SOFTSTANDBY:
case PWR_SOFTRESUME:
break;
}
splx(s); splx(s);
return true;
static bool
ym_resume(device_t self PMF_FN_ARGS)
{
struct ym_softc *sc = device_private(self);
int i, xmax;
int s;
sc = v;
DPRINTF(("%s: ym_power_hook: resume\n", DVNAME(sc)));
s = splaudio();
/*
* resuming...
*/
ym_chip_powerup(sc, 1);
ym_init(sc); /* power-on CODEC */
/* Restore control registers. */
xmax = YM_IS_SA3(sc)? YM_SAVE_REG_MAX_SA3 : YM_SAVE_REG_MAX_SA2;
for (i = SA3_PWR_MNG + 1; i <= xmax; i++) {
if (i == SA3_SB_SCAN || i == SA3_SB_SCAN_DATA ||
i == SA3_DPWRDWN)
continue;
ym_write(sc, i, sc->sc_sa3_scan[i]);
}
/* Restore CODEC registers (including mixer). */
ym_restore_codec_regs(sc);
/* Restore global/digital power-down state. */
ym_write(sc, SA3_PWR_MNG, sc->sc_sa3_scan[SA3_PWR_MNG]);
if (YM_IS_SA3(sc))
ym_write(sc, SA3_DPWRDWN, sc->sc_sa3_scan[SA3_DPWRDWN]);
splx(s);
return true;
} }
int int

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ne_pcmcia.c,v 1.157 2009/09/05 14:44:59 tsutsui Exp $ */ /* $NetBSD: if_ne_pcmcia.c,v 1.158 2010/01/02 01:43:11 christos Exp $ */
/* /*
* Copyright (c) 1997 Marc Horowitz. All rights reserved. * Copyright (c) 1997 Marc Horowitz. All rights reserved.
@ -30,7 +30,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ne_pcmcia.c,v 1.157 2009/09/05 14:44:59 tsutsui Exp $"); __KERNEL_RCSID(0, "$NetBSD: if_ne_pcmcia.c,v 1.158 2010/01/02 01:43:11 christos Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -80,7 +80,6 @@ struct ne_pcmcia_softc {
struct pcmcia_function *sc_pf; /* our PCMCIA function */ struct pcmcia_function *sc_pf; /* our PCMCIA function */
int sc_state; int sc_state;
#define NE_PCMCIA_ATTACHED 3 #define NE_PCMCIA_ATTACHED 3
void *sc_powerhook; /* power management hook */
}; };
u_int8_t *ne_pcmcia_get_enaddr(struct ne_pcmcia_softc *, int, u_int8_t *ne_pcmcia_get_enaddr(struct ne_pcmcia_softc *, int,
@ -733,13 +732,9 @@ found:
if (ne2000_attach(nsc, enaddr)) if (ne2000_attach(nsc, enaddr))
goto fail2; goto fail2;
/* dopowerhooks(9) - deprecated, only called by hpcs* apmdev(4) */ if (!pmf_device_register(self, ne2000_suspend, ne2000_resume)) {
psc->sc_powerhook = powerhook_establish(device_xname(self), aprint_error_dev(self, "cannot set power mgmt handler\n");
ne2000_power, nsc); }
if (psc->sc_powerhook == NULL)
aprint_error_dev(self,
"WARNING: unable to establish power hook\n");
/* pmf(9) power hooks */ /* pmf(9) power hooks */
if (pmf_device_register(self, ne2000_suspend, ne2000_resume)) { if (pmf_device_register(self, ne2000_suspend, ne2000_resume)) {
#if 0 /* XXX: notyet: if_stop is NULL! */ #if 0 /* XXX: notyet: if_stop is NULL! */
@ -768,9 +763,7 @@ ne_pcmcia_detach(device_t self, int flags)
if (psc->sc_state != NE_PCMCIA_ATTACHED) if (psc->sc_state != NE_PCMCIA_ATTACHED)
return (0); return (0);
if (psc->sc_powerhook != NULL) pmf_device_deregister(self);
powerhook_disestablish(psc->sc_powerhook);
error = ne2000_detach(&psc->sc_ne2000, flags); error = ne2000_detach(&psc->sc_ne2000, flags);
if (error) if (error)
return (error); return (error);

View File

@ -1,4 +1,4 @@
/* $NetBSD: dbri.c,v 1.25 2009/09/20 08:24:04 tsutsui Exp $ */ /* $NetBSD: dbri.c,v 1.26 2010/01/02 01:43:42 christos Exp $ */
/* /*
* Copyright (C) 1997 Rudolf Koenig (rfkoenig@immd4.informatik.uni-erlangen.de) * Copyright (C) 1997 Rudolf Koenig (rfkoenig@immd4.informatik.uni-erlangen.de)
@ -34,7 +34,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: dbri.c,v 1.25 2009/09/20 08:24:04 tsutsui Exp $"); __KERNEL_RCSID(0, "$NetBSD: dbri.c,v 1.26 2010/01/02 01:43:42 christos Exp $");
#include "audio.h" #include "audio.h"
#if NAUDIO > 0 #if NAUDIO > 0
@ -162,7 +162,9 @@ static void dbri_free(void *, void *, struct malloc_type *);
static paddr_t dbri_mappage(void *, void *, off_t, int); static paddr_t dbri_mappage(void *, void *, off_t, int);
static void dbri_set_power(struct dbri_softc *, int); static void dbri_set_power(struct dbri_softc *, int);
static void dbri_bring_up(struct dbri_softc *); static void dbri_bring_up(struct dbri_softc *);
static void dbri_powerhook(int, void *); static void dbri_sus(int, void *);
static bool dbri_suspend(device_t PMF_FN_PROTO);
static bool dbri_resume(device_t PMF_FN_PROTO);
/* stupid support routines */ /* stupid support routines */
static uint32_t reverse_bytes(uint32_t, int); static uint32_t reverse_bytes(uint32_t, int);
@ -294,7 +296,10 @@ dbri_attach_sbus(device_t parent, device_t self, void *aux)
sc->sc_have_powerctl = 1; sc->sc_have_powerctl = 1;
sc->sc_powerstate = 0; sc->sc_powerstate = 0;
dbri_set_power(sc, 1); dbri_set_power(sc, 1);
powerhook_establish(device_xname(self), dbri_powerhook, sc); if (!pmf_device_register(self, dbri_suspend, dbri_resume)) {
aprint_error_dev(self,
"cannot set power mgmt handler\n");
}
} else { } else {
/* we can't control power so we're always up */ /* we can't control power so we're always up */
sc->sc_have_powerctl = 0; sc->sc_have_powerctl = 0;
@ -374,7 +379,6 @@ dbri_attach_sbus(device_t parent, device_t self, void *aux)
sc->sc_refcount = 0; sc->sc_refcount = 0;
sc->sc_playing = 0; sc->sc_playing = 0;
sc->sc_recording = 0; sc->sc_recording = 0;
sc->sc_pmgrstate = PWR_RESUME;
config_interrupts(self, &dbri_config_interrupts); config_interrupts(self, &dbri_config_interrupts);
return; return;
@ -2169,45 +2173,38 @@ dbri_close(void *cookie)
sc->sc_recording = 0; sc->sc_recording = 0;
} }
static void static bool
dbri_powerhook(int why, void *cookie) dbri_suspend(device_t self PMF_FN_ARGS)
{ {
struct dbri_softc *sc = cookie; struct dbri_softc *sc = device_private(self);
if (why == sc->sc_pmgrstate) dbri_set_power(sc, 0);
return; return true;
}
switch(why) static bool
{ dbri_resume(device_t self PMF_FN_ARGS)
case PWR_SUSPEND: {
dbri_set_power(sc, 0); if (sc->sc_powerstate != 0)
break; break;
case PWR_RESUME: aprint_verbose("resume: %d\n", sc->sc_refcount);
if (sc->sc_powerstate != 0) if (sc->sc_playing) {
break; volatile uint32_t *cmd;
aprint_verbose("resume: %d\n", sc->sc_refcount); int s;
sc->sc_pmgrstate = PWR_RESUME;
if (sc->sc_playing) {
volatile uint32_t *cmd;
int s;
dbri_bring_up(sc); dbri_bring_up(sc);
s = splsched(); s = splsched();
cmd = dbri_command_lock(sc); cmd = dbri_command_lock(sc);
*(cmd++) = DBRI_CMD(DBRI_COMMAND_SDP, *(cmd++) = DBRI_CMD(DBRI_COMMAND_SDP,
0, sc->sc_pipe[4].sdp | 0, sc->sc_pipe[4].sdp |
DBRI_SDP_VALID_POINTER | DBRI_SDP_VALID_POINTER |
DBRI_SDP_EVERY | DBRI_SDP_CLEAR); DBRI_SDP_EVERY | DBRI_SDP_CLEAR);
*(cmd++) = sc->sc_dmabase + *(cmd++) = sc->sc_dmabase +
dbri_dma_off(xmit, 0); dbri_dma_off(xmit, 0);
dbri_command_send(sc, cmd); dbri_command_send(sc, cmd);
splx(s); splx(s);
}
break;
default:
return;
} }
sc->sc_pmgrstate = why; return true;
} }
#endif /* NAUDIO > 0 */ #endif /* NAUDIO > 0 */