From 664df27b219fc5e2e61089c0c1a9a70d91e6b6c9 Mon Sep 17 00:00:00 2001 From: nonaka Date: Thu, 29 Jan 2009 16:00:33 +0000 Subject: [PATCH] Use pmf(9) instead of powerhook_*. --- sys/arch/zaurus/dev/zaudio.c | 61 +++++++++++++----------------------- sys/arch/zaurus/dev/zkbd.c | 25 +++++++-------- sys/arch/zaurus/dev/zlcd.c | 54 ++++++++++++++++++------------- sys/arch/zaurus/dev/zssp.c | 27 ++++++++-------- 4 files changed, 78 insertions(+), 89 deletions(-) diff --git a/sys/arch/zaurus/dev/zaudio.c b/sys/arch/zaurus/dev/zaudio.c index 0d2a3d531b61..2c3b65b2500e 100644 --- a/sys/arch/zaurus/dev/zaudio.c +++ b/sys/arch/zaurus/dev/zaudio.c @@ -1,4 +1,4 @@ -/* $NetBSD: zaudio.c,v 1.6 2009/01/29 12:28:15 nonaka Exp $ */ +/* $NetBSD: zaudio.c,v 1.7 2009/01/29 16:00:33 nonaka Exp $ */ /* $OpenBSD: zaurus_audio.c,v 1.8 2005/08/18 13:23:02 robert Exp $ */ /* @@ -60,8 +60,8 @@ __KERNEL_RCSID(0, "$NetBSD"); static int zaudio_match(device_t, cfdata_t, void *); static void zaudio_attach(device_t, device_t, void *); -static int zaudio_detach(device_t, int); -static void zaudio_power(int, void *); +static bool zaudio_suspend(device_t dv PMF_FN_ARGS); +static bool zaudio_resume(device_t dv PMF_FN_ARGS); #define ZAUDIO_OP_SPKR 0 #define ZAUDIO_OP_HP 1 @@ -89,7 +89,6 @@ struct zaudio_softc { /* i2c device softc */ struct pxa2x0_i2c_softc sc_i2c; - void *sc_powerhook; int sc_playing; struct zaudio_volume sc_volume[2]; @@ -101,7 +100,7 @@ struct zaudio_softc { }; CFATTACH_DECL_NEW(zaudio, sizeof(struct zaudio_softc), - zaudio_match, zaudio_attach, zaudio_detach, NULL); + zaudio_match, zaudio_attach, NULL, NULL); static struct audio_device wm8750_device = { "WM8750", @@ -221,12 +220,9 @@ zaudio_attach(device_t parent, device_t self, void *aux) aprint_normal(": I2C, I2S, WM8750 Audio\n"); aprint_naive("\n"); - sc->sc_powerhook = powerhook_establish(device_xname(sc->sc_dev), - zaudio_power, sc); - if (sc->sc_powerhook == NULL) { - aprint_error_dev(sc->sc_dev, "unable to establish powerhook\n"); - return; - } + if (!pmf_device_register(sc->sc_dev, zaudio_suspend, zaudio_resume)) + aprint_error_dev(sc->sc_dev, + "couldn't establish power handler\n"); sc->sc_i2s.sc_iot = pxa->pxa_iot; sc->sc_i2s.sc_dmat = pxa->pxa_dmat; @@ -247,7 +243,6 @@ zaudio_attach(device_t parent, device_t self, void *aux) pxa2x0_i2c_open(&sc->sc_i2c); rv = wm8750_write(sc, RESET_REG, 0); pxa2x0_i2c_close(&sc->sc_i2c); - if (rv) { aprint_error_dev(sc->sc_dev, "codec failed to respond\n"); goto fail_probe; @@ -279,43 +274,30 @@ fail_probe: fail_i2c: pxa2x0_i2s_detach_sub(&sc->sc_i2s); fail_i2s: - powerhook_disestablish(sc->sc_powerhook); + pmf_device_deregister(self); } -static int -zaudio_detach(device_t self, int flags) +static bool +zaudio_suspend(device_t dv PMF_FN_ARGS) { - struct zaudio_softc *sc = device_private(self); + struct zaudio_softc *sc = device_private(dv); - if (sc->sc_powerhook != NULL) { - powerhook_disestablish(sc->sc_powerhook); - sc->sc_powerhook = NULL; - } + callout_stop(&sc->sc_to); + zaudio_standby(sc); - pxa2x0_i2c_detach_sub(&sc->sc_i2c); - pxa2x0_i2s_detach_sub(&sc->sc_i2s); - - return 0; + return true; } -static void -zaudio_power(int why, void *arg) +static bool +zaudio_resume(device_t dv PMF_FN_ARGS) { - struct zaudio_softc *sc = arg; + struct zaudio_softc *sc = device_private(dv); - switch (why) { - case PWR_STANDBY: - case PWR_SUSPEND: - callout_stop(&sc->sc_to); - zaudio_standby(sc); - break; + pxa2x0_i2s_init(&sc->sc_i2s); + pxa2x0_i2c_init(&sc->sc_i2c); + zaudio_init(sc); - case PWR_RESUME: - pxa2x0_i2s_init(&sc->sc_i2s); - pxa2x0_i2c_init(&sc->sc_i2c); - zaudio_init(sc); - break; - } + return true; } void @@ -345,7 +327,6 @@ zaudio_init(struct zaudio_softc *sc) /* Assume that the jack state has changed. */ zaudio_jack(sc); - } static int diff --git a/sys/arch/zaurus/dev/zkbd.c b/sys/arch/zaurus/dev/zkbd.c index 8f10177d9513..6bb35b5cc7a5 100644 --- a/sys/arch/zaurus/dev/zkbd.c +++ b/sys/arch/zaurus/dev/zkbd.c @@ -1,4 +1,4 @@ -/* $NetBSD: zkbd.c,v 1.8 2009/01/29 12:28:15 nonaka Exp $ */ +/* $NetBSD: zkbd.c,v 1.9 2009/01/29 16:00:33 nonaka Exp $ */ /* $OpenBSD: zaurus_kbd.c,v 1.28 2005/12/21 20:36:03 deraadt Exp $ */ /* @@ -18,7 +18,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: zkbd.c,v 1.8 2009/01/29 12:28:15 nonaka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: zkbd.c,v 1.9 2009/01/29 16:00:33 nonaka Exp $"); #include "opt_wsdisplay_compat.h" #include "lcd.h" @@ -116,7 +116,6 @@ struct zkbd_softc { char sc_rep[MAXKEYS]; int sc_nrep; #endif - void *sc_powerhook; }; static struct zkbd_softc *zkbd_sc; @@ -132,7 +131,7 @@ static void zkbd_poll(void *v); static int zkbd_on(void *v); static int zkbd_sync(void *v); static int zkbd_hinge(void *v); -static void zkbd_power(int why, void *arg); +static bool zkbd_resume(device_t dv PMF_FN_ARGS); int zkbd_modstate; @@ -215,12 +214,9 @@ zkbd_attach(device_t parent, device_t self, void *aux) return; } - sc->sc_powerhook = powerhook_establish(device_xname(sc->sc_dev), - zkbd_power, sc); - if (sc->sc_powerhook == NULL) { - aprint_error_dev(sc->sc_dev, "unable to establish powerhook\n"); - return; - } + if (!pmf_device_register(sc->sc_dev, NULL, zkbd_resume)) + aprint_error_dev(sc->sc_dev, + "couldn't establish power handler\n"); sc->sc_okeystate = malloc(sc->sc_nsense * sc->sc_nstrobe, M_DEVBUF, M_NOWAIT); @@ -597,9 +593,12 @@ zkbd_cnpollc(void *v, int on) { } -static void -zkbd_power(int why, void *arg) +static bool +zkbd_resume(device_t dv PMF_FN_ARGS) { + struct zkbd_softc *sc = device_private(dv); - zkbd_hinge(arg); + zkbd_hinge(sc); + + return true; } diff --git a/sys/arch/zaurus/dev/zlcd.c b/sys/arch/zaurus/dev/zlcd.c index dc6198e074f9..cb771c330dc0 100644 --- a/sys/arch/zaurus/dev/zlcd.c +++ b/sys/arch/zaurus/dev/zlcd.c @@ -1,4 +1,4 @@ -/* $NetBSD: zlcd.c,v 1.8 2009/01/29 12:28:15 nonaka Exp $ */ +/* $NetBSD: zlcd.c,v 1.9 2009/01/29 16:00:33 nonaka Exp $ */ /* $OpenBSD: zaurus_lcd.c,v 1.20 2006/06/02 20:50:14 miod Exp $ */ /* NetBSD: lubbock_lcd.c,v 1.1 2003/08/09 19:38:53 bsh Exp */ @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: zlcd.c,v 1.8 2009/01/29 12:28:15 nonaka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: zlcd.c,v 1.9 2009/01/29 16:00:33 nonaka Exp $"); #include #include @@ -154,6 +154,9 @@ static void lcd_attach(device_t, device_t, void *); CFATTACH_DECL_NEW(zlcd, sizeof(struct pxa2x0_lcd_softc), lcd_match, lcd_attach, NULL, NULL); +static bool lcd_suspend(device_t dv PMF_FN_ARGS); +static bool lcd_resume(device_t dv PMF_FN_ARGS); + void lcd_cnattach(void); int lcd_max_brightness(void); int lcd_get_brightness(void); @@ -162,7 +165,6 @@ void lcd_set_brightness_internal(int); int lcd_get_backlight(void); void lcd_set_backlight(int); void lcd_blank(int); -void lcd_power(int, void *); static int lcd_match(device_t parent, cfdata_t cf, void *aux) @@ -191,7 +193,8 @@ lcd_attach(device_t parent, device_t self, void *aux) /* Start with approximately 40% of full brightness. */ lcd_set_brightness(3); - (void) powerhook_establish(device_xname(sc->dev), lcd_power, sc); + if (!pmf_device_register(sc->dev, lcd_suspend, lcd_resume)) + aprint_error_dev(sc->dev, "couldn't establish power handler\n"); } void @@ -201,6 +204,31 @@ lcd_cnattach(void) pxa2x0_lcd_cnattach(&lcd_std_screen, CURRENT_DISPLAY); } +/* + * power management + */ +static bool +lcd_suspend(device_t dv PMF_FN_ARGS) +{ + struct pxa2x0_lcd_softc *sc = device_private(dv); + + lcd_set_brightness(0); + pxa2x0_lcd_suspend(sc); + + return true; +} + +static bool +lcd_resume(device_t dv PMF_FN_ARGS) +{ + struct pxa2x0_lcd_softc *sc = device_private(dv); + + pxa2x0_lcd_resume(sc); + lcd_set_brightness(lcd_get_brightness()); + + return true; +} + /* * wsdisplay accessops overrides */ @@ -493,21 +521,3 @@ lcd_blank(int blank) lcd_set_brightness(lcd_get_brightness()); } } - -void -lcd_power(int why, void *v) -{ - - switch (why) { - case PWR_SUSPEND: - case PWR_STANDBY: - lcd_set_brightness(0); - pxa2x0_lcd_power(why, v); - break; - - case PWR_RESUME: - pxa2x0_lcd_power(why, v); - lcd_set_brightness(lcd_get_brightness()); - break; - } -} diff --git a/sys/arch/zaurus/dev/zssp.c b/sys/arch/zaurus/dev/zssp.c index 7c7b80f44239..93de3ae0f0c2 100644 --- a/sys/arch/zaurus/dev/zssp.c +++ b/sys/arch/zaurus/dev/zssp.c @@ -1,4 +1,4 @@ -/* $NetBSD: zssp.c,v 1.5 2009/01/29 12:51:15 nonaka Exp $ */ +/* $NetBSD: zssp.c,v 1.6 2009/01/29 16:00:33 nonaka Exp $ */ /* $OpenBSD: zaurus_ssp.c,v 1.6 2005/04/08 21:58:49 uwe Exp $ */ /* @@ -18,7 +18,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: zssp.c,v 1.5 2009/01/29 12:51:15 nonaka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: zssp.c,v 1.6 2009/01/29 16:00:33 nonaka Exp $"); #include #include @@ -54,7 +54,7 @@ CFATTACH_DECL_NEW(zssp, sizeof(struct zssp_softc), zssp_match, zssp_attach, NULL, NULL); static void zssp_init(void); -static void zssp_powerhook(int, void *); +static bool zssp_resume(device_t dv PMF_FN_ARGS); static struct zssp_softc *zssp_sc; @@ -86,10 +86,9 @@ zssp_attach(device_t parent, device_t self, void *aux) return; } - if (powerhook_establish(device_xname(sc->sc_dev), zssp_powerhook, sc) - == NULL) { - aprint_error_dev(sc->sc_dev, "can't establish power hook\n"); - } + if (!pmf_device_register(sc->sc_dev, NULL, zssp_resume)) + aprint_error_dev(sc->sc_dev, + "couldn't establish power handler\n"); zssp_init(); } @@ -116,16 +115,16 @@ zssp_init(void) pxa2x0_gpio_set_function(GPIO_TG_CS_C3000, GPIO_OUT|GPIO_SET); } -static void -zssp_powerhook(int why, void *arg) +static bool +zssp_resume(device_t dv PMF_FN_ARGS) { int s; - if (why == PWR_RESUME) { - s = splhigh(); - zssp_init(); - splx(s); - } + s = splhigh(); + zssp_init(); + splx(s); + + return true; } /*