Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/isa Modularize the spkr(4) driver (i386 and amd64 on...



details:   https://anonhg.NetBSD.org/src/rev/4e5f7b115c43
branches:  trunk
changeset: 808424:4e5f7b115c43
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sun May 17 05:20:37 2015 +0000

description:
Modularize the spkr(4) driver (i386 and amd64 only).  Adapt parent
pcppi(4) driver to be able to handle rescan().

diffstat:

 sys/dev/isa/pcppi.c |  24 ++++++++++++++---
 sys/dev/isa/spkr.c  |  69 +++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 84 insertions(+), 9 deletions(-)

diffs (181 lines):

diff -r 2cbad842dc72 -r 4e5f7b115c43 sys/dev/isa/pcppi.c
--- a/sys/dev/isa/pcppi.c       Sun May 17 04:59:43 2015 +0000
+++ b/sys/dev/isa/pcppi.c       Sun May 17 05:20:37 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcppi.c,v 1.43 2014/12/08 16:16:45 msaitoh Exp $ */
+/* $NetBSD: pcppi.c,v 1.44 2015/05/17 05:20:37 pgoyette Exp $ */
 
 /*
  * Copyright (c) 1996 Carnegie-Mellon University.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.43 2014/12/08 16:16:45 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.44 2015/05/17 05:20:37 pgoyette Exp $");
 
 #include "attimer.h"
 
@@ -61,10 +61,11 @@
 int    pcppi_match(device_t, cfdata_t, void *);
 void   pcppi_isa_attach(device_t, device_t, void *);
 void   pcppi_childdet(device_t, device_t);
+int    pcppi_rescan(device_t, const char *, const int *);
 
 CFATTACH_DECL3_NEW(pcppi, sizeof(struct pcppi_softc),
-    pcppi_match, pcppi_isa_attach, pcppi_detach, NULL, NULL, pcppi_childdet,
-    DVF_DETACH_SHUTDOWN);
+    pcppi_match, pcppi_isa_attach, pcppi_detach, NULL, pcppi_rescan,
+    pcppi_childdet, DVF_DETACH_SHUTDOWN);
 
 static int pcppisearch(device_t, cfdata_t, const int *, void *);
 static void pcppi_bell_stop(struct pcppi_softc *);
@@ -214,7 +215,6 @@
 void
 pcppi_attach(struct pcppi_softc *sc)
 {
-        struct pcppi_attach_args pa;
        device_t self = sc->sc_dv;
 
        callout_init(&sc->sc_bell_ch, CALLOUT_MPSAFE);
@@ -233,8 +233,22 @@
        if (!pmf_device_register(self, NULL, NULL))
                aprint_error_dev(self, "couldn't establish power handler\n");
 
+       pcppi_rescan(self, "pcppi", NULL);
+}
+
+int
+pcppi_rescan(device_t self, const char *ifattr, const int *flags)
+{
+       struct pcppi_softc *sc = device_private(self);
+        struct pcppi_attach_args pa;
+
+       if (!ifattr_match(ifattr, "pcppi"))
+               return 0;
+
        pa.pa_cookie = sc;
        config_search_loc(pcppisearch, sc->sc_dv, "pcppi", NULL, &pa);
+
+       return 0;
 }
 
 static int
diff -r 2cbad842dc72 -r 4e5f7b115c43 sys/dev/isa/spkr.c
--- a/sys/dev/isa/spkr.c        Sun May 17 04:59:43 2015 +0000
+++ b/sys/dev/isa/spkr.c        Sun May 17 05:20:37 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spkr.c,v 1.35 2014/07/25 08:10:37 dholland Exp $       */
+/*     $NetBSD: spkr.c,v 1.36 2015/05/17 05:20:37 pgoyette Exp $       */
 
 /*
  * Copyright (c) 1990 Eric S. Raymond (esr%snark.thyrsus.com@localhost)
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.35 2014/07/25 08:10:37 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.36 2015/05/17 05:20:37 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -51,6 +51,7 @@
 #include <sys/errno.h>
 #include <sys/device.h>
 #include <sys/malloc.h>
+#include <sys/module.h>
 #include <sys/uio.h>
 #include <sys/proc.h>
 #include <sys/ioctl.h>
@@ -64,9 +65,19 @@
 
 int spkrprobe(device_t, cfdata_t, void *);
 void spkrattach(device_t, device_t, void *);
+int spkrdetach(device_t, int);
+
+#include "ioconf.h"
+
+MODULE(MODULE_CLASS_DRIVER, spkr, NULL /* "pcppi" */);
+
+#ifdef _MODULE
+#include "ioconf.c"
+#endif
+
 
 CFATTACH_DECL_NEW(spkr, 0,
-    spkrprobe, spkrattach, NULL, NULL);
+    spkrprobe, spkrattach, spkrdetach, NULL);
 
 dev_type_open(spkropen);
 dev_type_close(spkrclose);
@@ -176,7 +187,7 @@
 /* 5 */ 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951,
 /* 6 */ 4186, 4435, 4698, 4978, 5274, 5588, 5920, 6272, 6644, 7040, 7459, 7902,
 };
-#define NOCTAVES (__arraycount(pitchtab) / OCTAVE_NOTES)
+#define NOCTAVES (int)(__arraycount(pitchtab) / OCTAVE_NOTES)
 
 static void
 playinit(void)
@@ -424,6 +435,17 @@
 }
 
 int
+spkrdetach(device_t self, int flags)
+{
+
+       pmf_device_deregister(self);
+       spkr_attached = 0;
+       ppicookie = NULL;
+
+       return 0;
+}
+
+int
 spkropen(dev_t dev, int        flags, int mode, struct lwp *l)
 {
 #ifdef SPKRDEBUG
@@ -524,4 +546,43 @@
     return(0);
 }
 
+static int
+spkr_modcmd(modcmd_t cmd, void *arg)
+{
+#ifdef _MODULE
+       devmajor_t bmajor, cmajor;
+#endif
+       int error = 0;
+
+#ifdef _MODULE
+       switch(cmd) {
+       case MODULE_CMD_INIT:
+               bmajor = cmajor = -1;
+               error = devsw_attach(spkr_cd.cd_name, NULL, &bmajor,
+                   &spkr_cdevsw, &cmajor);
+               if (error)
+                       break;
+
+               error = config_init_component(cfdriver_ioconf_spkr,
+                       cfattach_ioconf_spkr, cfdata_ioconf_spkr);
+               if (error) {
+                       devsw_detach(NULL, &spkr_cdevsw);
+               }
+               break;
+
+       case MODULE_CMD_FINI:
+               if (spkr_active)
+                       return EBUSY;
+               error = config_fini_component(cfdriver_ioconf_spkr,
+                       cfattach_ioconf_spkr, cfdata_ioconf_spkr);
+               devsw_detach(NULL, &spkr_cdevsw);
+               break;
+       default:
+               error = ENOTTY;
+               break;
+       }
+#endif
+
+       return error;
+}
 /* spkr.c ends here */



Home | Main Index | Thread Index | Old Index