Module Name:    src
Committed By:   pgoyette
Date:           Sun May 17 05:20:37 UTC 2015

Modified Files:
        src/sys/dev/isa: pcppi.c spkr.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/isa/pcppi.c
cvs rdiff -u -r1.35 -r1.36 src/sys/dev/isa/spkr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/isa/pcppi.c
diff -u src/sys/dev/isa/pcppi.c:1.43 src/sys/dev/isa/pcppi.c:1.44
--- src/sys/dev/isa/pcppi.c:1.43	Mon Dec  8 16:16:45 2014
+++ src/sys/dev/isa/pcppi.c	Sun May 17 05:20:37 2015
@@ -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 @@ void	pcppi_pckbd_bell(void *, u_int, u_i
 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 @@ pcppi_detach(device_t self, int flags)
 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 @@ pcppi_attach(struct pcppi_softc *sc)
 	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

Index: src/sys/dev/isa/spkr.c
diff -u src/sys/dev/isa/spkr.c:1.35 src/sys/dev/isa/spkr.c:1.36
--- src/sys/dev/isa/spkr.c:1.35	Fri Jul 25 08:10:37 2014
+++ src/sys/dev/isa/spkr.c	Sun May 17 05:20:37 2015
@@ -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 (e...@snark.thyrsus.com)
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.3
 #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 @@ __KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.3
 
 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 @@ static const int pitchtab[] =
 /* 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 @@ spkrattach(device_t parent, device_t sel
 }
 
 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 @@ spkrioctl(dev_t dev, u_long cmd, void *d
     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 */

Reply via email to