xref: /netbsd-src/sys/dev/midi_seq_mod.c (revision a352468a150c86f417c3d5bb3ff885e3504aa167)
1 /*	$NetBSD: midi_seq_mod.c,v 1.2 2022/06/04 20:12:10 pgoyette Exp $	*/
2 
3 /*
4  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Lennart Augustsson (augustss@NetBSD.org), (MIDI FST and Active
9  * Sense handling) Chapman Flack (chap@NetBSD.org), and Andrew Doran.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: midi_seq_mod.c,v 1.2 2022/06/04 20:12:10 pgoyette Exp $");
35 
36 #ifdef _KERNEL_OPT
37 #include "midi.h"
38 #endif
39 
40 #include <sys/param.h>
41 #include <sys/ioctl.h>
42 #include <sys/fcntl.h>
43 #include <sys/vnode.h>
44 #include <sys/select.h>
45 #include <sys/poll.h>
46 #include <sys/proc.h>
47 #include <sys/systm.h>
48 #include <sys/callout.h>
49 #include <sys/syslog.h>
50 #include <sys/kernel.h>
51 #include <sys/signalvar.h>
52 #include <sys/conf.h>
53 #include <sys/audioio.h>
54 #include <sys/midiio.h>
55 #include <sys/device.h>
56 #include <sys/intr.h>
57 #include <sys/module.h>
58 
59 #include <dev/audio/audio_if.h>
60 #include <dev/midi_if.h>
61 #include <dev/midivar.h>
62 
63 #include "ioconf.h"
64 
65 extern struct cfdriver sequencer_cd;
66 extern struct cdevsw midi_cdevsw;
67 extern struct cdevsw sequencer_cdevsw;
68 
69 #ifdef _MODULE
70 #include "ioconf.c"
71 
72 CFDRIVER_DECL(sequencer, DV_DULL, NULL);
73 
74 devmajor_t midi_bmajor = -1, midi_cmajor = -1;
75 devmajor_t sequencer_bmajor = -1, sequencer_cmajor = -1;
76 #endif
77 
78 MODULE(MODULE_CLASS_DRIVER, midi_seq, "audio");
79 
80 static int
midi_seq_modcmd(modcmd_t cmd,void * arg)81 midi_seq_modcmd(modcmd_t cmd, void *arg)
82 {
83 	int error = 0;
84 
85 #ifdef _MODULE
86 	switch (cmd) {
87 	case MODULE_CMD_INIT:
88 #if NMIDI > 0
89 		error = devsw_attach(midi_cd.cd_name, NULL, &midi_bmajor,
90 		    &midi_cdevsw, &midi_cmajor);
91 		if (error)
92 			break;
93 #endif
94 
95 #if NSEQUENCER > 0
96 		error = devsw_attach(sequencer_cd.cd_name,
97 		    NULL, &sequencer_bmajor,
98 		    &sequencer_cdevsw, &sequencer_cmajor);
99 		if (error) {
100 #if NMIDI > 0
101 			devsw_detach(NULL, &midi_cdevsw);
102 #endif
103 			break;
104 		}
105 #endif
106 
107 #if NMIDI > 0
108 		error = config_init_component(cfdriver_ioconf_midi_seq,
109 		    cfattach_ioconf_midi_seq, cfdata_ioconf_midi_seq);
110 		if (error) {
111 #if NSEQUENCER > 0
112 			devsw_detach(NULL, &sequencer_cdevsw);
113 #endif
114 			devsw_detach(NULL, &midi_cdevsw);
115 #endif
116 		}
117 		break;
118 	case MODULE_CMD_FINI:
119 #if NMIDI > 0
120 		error = config_fini_component(cfdriver_ioconf_midi_seq,
121 		   cfattach_ioconf_midi_seq, cfdata_ioconf_midi_seq);
122 		if (error == 0) {
123 #endif
124 #if NSEQUENCER > 0
125 			devsw_detach(NULL, &sequencer_cdevsw);
126 #endif
127 #if NMIDI > 0
128 			devsw_detach(NULL, &midi_cdevsw);
129 #endif
130 		}
131 		break;
132 	default:
133 		error = ENOTTY;
134 		break;
135 	}
136 #endif
137 
138 	return error;
139 }
140