Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev convert to pmf



details:   https://anonhg.NetBSD.org/src/rev/14c96bd60cd3
branches:  trunk
changeset: 750471:14c96bd60cd3
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jan 02 01:42:49 2010 +0000

description:
convert to pmf

diffstat:

 sys/dev/isa/ym.c              |  127 ++++++++++++++++++++++-------------------
 sys/dev/pcmcia/if_ne_pcmcia.c |   19 +----
 sys/dev/sbus/dbri.c           |   75 +++++++++++------------
 3 files changed, 109 insertions(+), 112 deletions(-)

diffs (truncated from 359 to 300 lines):

diff -r 740c11a8fba4 -r 14c96bd60cd3 sys/dev/isa/ym.c
--- a/sys/dev/isa/ym.c  Fri Jan 01 22:12:19 2010 +0000
+++ b/sys/dev/isa/ym.c  Sat Jan 02 01:42:49 2010 +0000
@@ -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.
@@ -60,7 +60,7 @@
  */
 
 #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 "opt_ym.h"
@@ -148,7 +148,6 @@
 #ifndef AUDIO_NO_POWER_CTL
 static void ym_save_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);
 static void ym_chip_powerdown(struct ym_softc *);
 static void ym_chip_powerup(struct ym_softc *, int);
@@ -163,6 +162,8 @@
 static void ym_set_mic_gain(struct ym_softc *, int);
 static void ym_set_3d(struct ym_softc *, mixer_ctrl_t *,
        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 = {
@@ -296,7 +297,10 @@
 #endif
        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
 
        /* Set tone control to the default position. */
@@ -1102,76 +1106,79 @@
  * Currently only the parameters, such as output gain, are restored.
  * DMA state should also be restored.  FIXME.
  */
-void
-ym_power_hook(int why, void *v)
+static bool
+ym_suspend(device_t self PMF_FN_ARGS)
 {
-       struct ym_softc *sc;
+       struct ym_softc *sc = device_private(self);
        int i, xmax;
        int s;
 
        sc = v;
-       DPRINTF(("%s: ym_power_hook: why = %d\n", DVNAME(sc), why));
+       DPRINTF(("%s: ym_power_hook: suspend\n", DVNAME(sc)));
 
        s = splaudio();
 
-       switch (why) {
-       case PWR_SUSPEND:
-       case PWR_STANDBY:
-               /*
-                * suspending...
-                */
-               callout_stop(&sc->sc_powerdown_ch);
-               if (sc->sc_turning_off)
-                       ym_powerdown_blocks(sc);
+       /*
+        * suspending...
+        */
+       callout_stop(&sc->sc_powerdown_ch);
+       if (sc->sc_turning_off)
+               ym_powerdown_blocks(sc);
 
-               /*
-                * Save CODEC registers.
-                * Note that the registers read incorrect
-                * if the CODEC part is in power-down mode.
-                */
-               if (sc->sc_on_blocks & YM_POWER_CODEC_DIGITAL)
-                       ym_save_codec_regs(sc);
+       /*
+        * Save CODEC registers.
+        * Note that the registers read incorrect
+        * if the CODEC part is in power-down mode.
+        */
+       if (sc->sc_on_blocks & YM_POWER_CODEC_DIGITAL)
+               ym_save_codec_regs(sc);
 
-               /*
-                * Save OPL3-SA3 control registers and power-down the chip.
-                * Note that the registers read incorrect
-                * if the chip is in global power-down mode.
-                */
-               sc->sc_sa3_scan[SA3_PWR_MNG] = ym_read(sc, SA3_PWR_MNG);
-               if (sc->sc_on_blocks)
-                       ym_chip_powerdown(sc);
-               break;
+       /*
+        * Save OPL3-SA3 control registers and power-down the chip.
+        * Note that the registers read incorrect
+        * if the chip is in global power-down mode.
+        */
+       sc->sc_sa3_scan[SA3_PWR_MNG] = ym_read(sc, SA3_PWR_MNG);
+       if (sc->sc_on_blocks)
+               ym_chip_powerdown(sc);
+       splx(s);
+       return true;
 
-       case PWR_RESUME:
-               /*
-                * resuming...
-                */
-               ym_chip_powerup(sc, 1);
-               ym_init(sc);            /* power-on CODEC */
+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 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 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;
-       }
+       /* 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
diff -r 740c11a8fba4 -r 14c96bd60cd3 sys/dev/pcmcia/if_ne_pcmcia.c
--- a/sys/dev/pcmcia/if_ne_pcmcia.c     Fri Jan 01 22:12:19 2010 +0000
+++ b/sys/dev/pcmcia/if_ne_pcmcia.c     Sat Jan 02 01:42:49 2010 +0000
@@ -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.
@@ -30,7 +30,7 @@
  */
 
 #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/systm.h>
@@ -80,7 +80,6 @@
        struct pcmcia_function *sc_pf;          /* our PCMCIA function */
        int sc_state;
 #define        NE_PCMCIA_ATTACHED      3
-       void *sc_powerhook;                     /* power management hook */
 };
 
 u_int8_t *ne_pcmcia_get_enaddr(struct ne_pcmcia_softc *, int,
@@ -733,13 +732,9 @@
        if (ne2000_attach(nsc, enaddr))
                goto fail2;
 
-       /* dopowerhooks(9) - deprecated, only called by hpcs* apmdev(4) */
-       psc->sc_powerhook = powerhook_establish(device_xname(self),
-           ne2000_power, nsc);
-       if (psc->sc_powerhook == NULL)
-               aprint_error_dev(self,
-                  "WARNING: unable to establish power hook\n");
-
+       if (!pmf_device_register(self, ne2000_suspend, ne2000_resume)) {
+               aprint_error_dev(self, "cannot set power mgmt handler\n");
+       }
        /* pmf(9) power hooks */
        if (pmf_device_register(self, ne2000_suspend, ne2000_resume)) {
 #if 0 /* XXX: notyet: if_stop is NULL! */
@@ -768,9 +763,7 @@
        if (psc->sc_state != NE_PCMCIA_ATTACHED)
                return (0);
 
-       if (psc->sc_powerhook != NULL)
-               powerhook_disestablish(psc->sc_powerhook);
-
+       pmf_device_deregister(self);
        error = ne2000_detach(&psc->sc_ne2000, flags);
        if (error)
                return (error);
diff -r 740c11a8fba4 -r 14c96bd60cd3 sys/dev/sbus/dbri.c
--- a/sys/dev/sbus/dbri.c       Fri Jan 01 22:12:19 2010 +0000
+++ b/sys/dev/sbus/dbri.c       Sat Jan 02 01:42:49 2010 +0000
@@ -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@localhost)
@@ -34,7 +34,7 @@
  */
 
 #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"
 #if NAUDIO > 0
@@ -162,7 +162,9 @@
 static paddr_t dbri_mappage(void *, void *, off_t, int);
 static void    dbri_set_power(struct dbri_softc *, int);
 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 */
 static uint32_t        reverse_bytes(uint32_t, int);
@@ -294,7 +296,10 @@
                sc->sc_have_powerctl = 1;
                sc->sc_powerstate = 0;
                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 {
                /* we can't control power so we're always up */
                sc->sc_have_powerctl = 0;
@@ -374,7 +379,6 @@
        sc->sc_refcount = 0;
        sc->sc_playing = 0;
        sc->sc_recording = 0;
-       sc->sc_pmgrstate = PWR_RESUME;
        config_interrupts(self, &dbri_config_interrupts);
 
        return;
@@ -2169,45 +2173,38 @@
        sc->sc_recording = 0;
 }
 
-static void
-dbri_powerhook(int why, void *cookie)
+static bool
+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)
-               return;



Home | Main Index | Thread Index | Old Index