Support pcppi(4) detachment.

Use device_t, device_private().  Get rid of a struct device * cast.
This commit is contained in:
dyoung 2008-01-10 07:58:39 +00:00
parent d3a283186c
commit 636e434283
5 changed files with 55 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcppi_acpi.c,v 1.8 2007/12/09 20:27:53 jmcneill Exp $ */
/* $NetBSD: pcppi_acpi.c,v 1.9 2008/01/10 07:58:39 dyoung Exp $ */
/*
* Copyright (c) 2002 Jared D. McNeill <jmcneill@invisible.ca>
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pcppi_acpi.c,v 1.8 2007/12/09 20:27:53 jmcneill Exp $");
__KERNEL_RCSID(0, "$NetBSD: pcppi_acpi.c,v 1.9 2008/01/10 07:58:39 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -47,15 +47,15 @@ __KERNEL_RCSID(0, "$NetBSD: pcppi_acpi.c,v 1.8 2007/12/09 20:27:53 jmcneill Exp
#include <dev/isa/pcppivar.h>
static int pcppi_acpi_match(struct device *, struct cfdata *, void *);
static void pcppi_acpi_attach(struct device *, struct device *, void *);
static int pcppi_acpi_match(device_t, struct cfdata *, void *);
static void pcppi_acpi_attach(device_t, device_t, void *);
struct pcppi_acpi_softc {
struct pcppi_softc sc_pcppi;
};
CFATTACH_DECL(pcppi_acpi, sizeof(struct pcppi_acpi_softc), pcppi_acpi_match,
pcppi_acpi_attach, NULL, NULL);
pcppi_acpi_attach, pcppi_detach, NULL);
/*
* Supported device IDs
@ -70,8 +70,7 @@ static const char * const pcppi_acpi_ids[] = {
* pcppi_acpi_match: autoconf(9) match routine
*/
static int
pcppi_acpi_match(struct device *parent, struct cfdata *match,
void *aux)
pcppi_acpi_match(device_t parent, struct cfdata *match, void *aux)
{
struct acpi_attach_args *aa = aux;
@ -85,10 +84,9 @@ pcppi_acpi_match(struct device *parent, struct cfdata *match,
* pcppi_acpi_attach: autoconf(9) attach routine
*/
static void
pcppi_acpi_attach(struct device *parent, struct device *self,
void *aux)
pcppi_acpi_attach(device_t parent, device_t self, void *aux)
{
struct pcppi_acpi_softc *asc = (struct pcppi_acpi_softc *)self;
struct pcppi_acpi_softc *asc = device_private(self);
struct pcppi_softc *sc = &asc->sc_pcppi;
struct acpi_attach_args *aa = aux;
struct acpi_resources res;
@ -113,7 +111,8 @@ pcppi_acpi_attach(struct device *parent, struct device *self,
}
sc->sc_iot = aa->aa_iot;
if (bus_space_map(sc->sc_iot, io->ar_base, io->ar_length,
sc->sc_size = io->ar_length;
if (bus_space_map(sc->sc_iot, io->ar_base, sc->sc_size,
0, &sc->sc_ppi_ioh)) {
aprint_error("%s: can't map i/o space\n", sc->sc_dv.dv_xname);
goto out;
@ -121,9 +120,6 @@ pcppi_acpi_attach(struct device *parent, struct device *self,
pcppi_attach(sc);
if (!pmf_device_register(self, NULL, NULL))
aprint_error_dev(self, "couldn't establish power handler\n");
out:
acpi_resource_cleanup(&res);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcppi.c,v 1.25 2007/12/16 19:01:36 christos Exp $ */
/* $NetBSD: pcppi.c,v 1.26 2008/01/10 07:58:39 dyoung Exp $ */
/*
* Copyright (c) 1996 Carnegie-Mellon University.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.25 2007/12/16 19:01:36 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.26 2008/01/10 07:58:39 dyoung Exp $");
#include "attimer.h"
@ -60,7 +60,7 @@ int pcppi_match(struct device *, struct cfdata *, void *);
void pcppi_isa_attach(struct device *, struct device *, void *);
CFATTACH_DECL(pcppi, sizeof(struct pcppi_softc),
pcppi_match, pcppi_isa_attach, NULL, NULL);
pcppi_match, pcppi_isa_attach, pcppi_detach, NULL);
static int pcppisearch(device_t, cfdata_t, const int *, void *);
static void pcppi_bell_stop(void*);
@ -159,7 +159,8 @@ pcppi_isa_attach(struct device *parent, struct device *self, void *aux)
sc->sc_iot = iot = ia->ia_iot;
if (bus_space_map(iot, IO_PPI, 1, 0, &sc->sc_ppi_ioh))
sc->sc_size = 1;
if (bus_space_map(iot, IO_PPI, sc->sc_size, 0, &sc->sc_ppi_ioh))
panic("pcppi_attach: couldn't map");
printf("\n");
@ -172,6 +173,29 @@ pcppi_isa_attach(struct device *parent, struct device *self, void *aux)
}
int
pcppi_detach(device_t self, int flags)
{
int rc;
struct pcppi_softc *sc = device_private(self);
if ((rc = config_detach_children(&sc->sc_dv, flags)) != 0)
return rc;
if (!pmf_device_register(self, NULL, NULL))
aprint_error_dev(self, "couldn't establish power handler\n");
#if NPCKBD > 0
pckbd_unhook_bell(pcppi_pckbd_bell, sc);
#endif
pcppi_bell_stop(sc);
callout_stop(&sc->sc_bell_ch);
callout_destroy(&sc->sc_bell_ch);
bus_space_unmap(sc->sc_iot, sc->sc_ppi_ioh, sc->sc_size);
return 0;
}
void
pcppi_attach(struct pcppi_softc *sc)
{
@ -186,7 +210,7 @@ pcppi_attach(struct pcppi_softc *sc)
pckbd_hookup_bell(pcppi_pckbd_bell, sc);
#endif
#if NATTIMER > 0
config_defer((struct device *)sc, pcppi_attach_speaker);
config_defer(&sc->sc_dv, pcppi_attach_speaker);
#endif
pa.pa_cookie = sc;

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcppivar.h,v 1.7 2005/12/11 12:22:03 christos Exp $ */
/* $NetBSD: pcppivar.h,v 1.8 2008/01/10 07:58:39 dyoung Exp $ */
/*
* Copyright (c) 1996 Carnegie-Mellon University.
@ -41,6 +41,7 @@ struct pcppi_softc {
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ppi_ioh;
bus_size_t sc_size;
struct attimer_softc *sc_timer;
struct callout sc_bell_ch;
@ -51,6 +52,7 @@ struct pcppi_softc {
};
void pcppi_attach(struct pcppi_softc *);
int pcppi_detach(device_t, int);
#define PCPPI_BELL_SLEEP 0x01 /* synchronous; sleep for complete */
#define PCPPI_BELL_POLL 0x02 /* synchronous; poll for complete */

View File

@ -1,4 +1,4 @@
/* $NetBSD: pckbd.c,v 1.18 2007/12/09 20:28:13 jmcneill Exp $ */
/* $NetBSD: pckbd.c,v 1.19 2008/01/10 07:58:39 dyoung Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -75,7 +75,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pckbd.c,v 1.18 2007/12/09 20:28:13 jmcneill Exp $");
__KERNEL_RCSID(0, "$NetBSD: pckbd.c,v 1.19 2008/01/10 07:58:39 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -642,6 +642,15 @@ pckbd_bell(u_int pitch, u_int period, u_int volume, int poll)
volume, poll);
}
void
pckbd_unhook_bell(void (*fn)(void *, u_int, u_int, u_int, int), void *arg)
{
if (pckbd_bell_fn != fn && pckbd_bell_fn_arg != arg)
return;
pckbd_bell_fn = NULL;
pckbd_bell_fn_arg = NULL;
}
void
pckbd_hookup_bell(void (*fn)(void *, u_int, u_int, u_int, int), void *arg)
{

View File

@ -1,6 +1,7 @@
/* $NetBSD: pckbdvar.h,v 1.3 2005/12/11 12:23:22 christos Exp $ */
/* $NetBSD: pckbdvar.h,v 1.4 2008/01/10 07:58:39 dyoung Exp $ */
#include <dev/pckbport/pckbportvar.h>
int pckbd_cnattach(pckbport_tag_t, int);
void pckbd_hookup_bell(void (*fn)(void *, u_int, u_int, u_int, int), void *);
void pckbd_unhook_bell(void (*fn)(void *, u_int, u_int, u_int, int), void *);