Index: sys/arch/amd64/conf/GENERIC =================================================================== RCS file: /cvsroot/src/sys/arch/amd64/conf/GENERIC,v retrieving revision 1.446 diff -u -p -u -r1.446 GENERIC --- sys/arch/amd64/conf/GENERIC 10 Dec 2016 23:03:23 -0000 1.446 +++ sys/arch/amd64/conf/GENERIC 13 Dec 2016 12:02:46 -0000 @@ -1108,10 +1108,12 @@ hdafg* at hdaudiobus? # Audio support audio* at audiobus? -# The spkr driver provides a simple tone interface to the built in speaker. -spkr0 at pcppi? # PC speaker +spkr_synth* at audio? # audio device synthesized speaker +spkr_pcppi* at pcppi? # PC speaker -#spkr0 at audio0 # PC speaker (synthesized) +# The spkr driver provides a simple tone interface to the built in speaker +# or audio device +spkr* at spkrbus? # MPU 401 UARTs #mpu* at isa? port 0x330 irq 9 # MPU401 or compatible card Index: sys/arch/amd64/conf/MODULAR =================================================================== RCS file: /cvsroot/src/sys/arch/amd64/conf/MODULAR,v retrieving revision 1.5 diff -u -p -u -r1.5 MODULAR --- sys/arch/amd64/conf/MODULAR 9 Sep 2016 21:10:56 -0000 1.5 +++ sys/arch/amd64/conf/MODULAR 13 Dec 2016 12:02:46 -0000 @@ -4,8 +4,8 @@ # XXX: incomplete include "arch/amd64/conf/GENERIC" -options MODULAR # new style module(7) framework -options MODULAR_DEFAULT_AUTOLOAD +#options MODULAR # new style module(7) framework +#options MODULAR_DEFAULT_AUTOLOAD -no acpicpu* at cpu? -no est0 at cpu0 @@ -135,3 +135,5 @@ options MODULAR_DEFAULT_AUTOLOAD # userland interface to drivers, including autoconf and properties retrieval -no pseudo-device drvctl + +options TRAP_SIGDEBUG Index: sys/conf/files =================================================================== RCS file: /cvsroot/src/sys/conf/files,v retrieving revision 1.1166 diff -u -p -u -r1.1166 files --- sys/conf/files 2 Nov 2016 00:11:59 -0000 1.1166 +++ sys/conf/files 13 Dec 2016 12:02:48 -0000 @@ -330,6 +330,7 @@ define onewirebus { } define pckbport {[slot = -1]} define pckbport_machdep_cnattach define firmload +define spkrbus { } include "dev/files.audio" @@ -344,6 +345,10 @@ file dev/dev_verbose.c device video attach video at videobus +# speaker devices, attaches to audio or pcppi drivers +device spkr {} +attach spkr at spkrbus + # DTV subsystem # include "dev/dtv/files.dtv" Index: sys/dev/files.audio =================================================================== RCS file: /cvsroot/src/sys/dev/files.audio,v retrieving revision 1.7 diff -u -p -u -r1.7 files.audio --- sys/dev/files.audio 11 Dec 2016 06:30:11 -0000 1.7 +++ sys/dev/files.audio 13 Dec 2016 12:02:48 -0000 @@ -17,8 +17,8 @@ device audio {}: audiodev, auconv, aurat attach audio at audiobus device midi: audio attach midi at midibus -device spkr: audiobell -attach spkr at audio with spkr_synth +device spkr_synth {}: spkrbus +attach spkr_synth at audio # console bell via audio device # @@ -26,7 +26,7 @@ define audiobell file dev/auconv.c auconv file dev/audio.c audio needs-flag -file dev/audiobell.c audiobell needs-flag +file dev/audiobell.c spkr_synth needs-flag file dev/aurateconv.c aurateconv needs-flag file dev/auvolconv.c auvolconv file dev/midi.c midi needs-flag Index: sys/dev/spkr.c =================================================================== RCS file: /cvsroot/src/sys/dev/spkr.c,v retrieving revision 1.3 diff -u -p -u -r1.3 spkr.c --- sys/dev/spkr.c 9 Dec 2016 05:17:03 -0000 1.3 +++ sys/dev/spkr.c 13 Dec 2016 12:02:48 -0000 @@ -62,6 +62,8 @@ __KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.3 #include #include +#define SPKRDEBUG + dev_type_open(spkropen); dev_type_close(spkrclose); dev_type_write(spkrwrite); @@ -82,9 +84,26 @@ const struct cdevsw spkr_cdevsw = { .d_flag = D_OTHER }; -static void playinit(void); -static void playtone(int, int, int); -static void playstring(char *, int); +struct spkr_softc { + device_t sc_dev; + int sc_octave; /* currently selected octave */ + int sc_whole; /* whole-note time at current tempo, in ticks */ + int sc_value; /* whole divisor for note time, quarter note = 1 */ + int sc_fill; /* controls spacing of notes */ + bool sc_octtrack; /* octave-tracking on? */ + bool sc_octprefix; /* override current octave-tracking state? */ + char *sc_inbuf; + + /* attachment-specific hooks */ + device_t sc_hwdev; + void (*sc_tone)(device_t, u_int, u_int); + void (*sc_rest)(device_t, int); +}; + + +static void playinit(struct spkr_softc *); +static void playtone(struct spkr_softc *, int, int, int); +static void playstring(struct spkr_softc *, char *, int); /**************** PLAY STRING INTERPRETER BEGINS HERE ********************** * @@ -96,13 +115,6 @@ static void playstring(char *, int); #define dtoi(c) ((c) - '0') -static int octave; /* currently selected octave */ -static int whole; /* whole-note time at current tempo, in ticks */ -static int value; /* whole divisor for note time, quarter note = 1 */ -static int fill; /* controls spacing of notes */ -static bool octtrack; /* octave-tracking on? */ -static bool octprefix; /* override current octave-tracking state? */ - /* * Magic number avoidance... */ @@ -144,221 +156,211 @@ static const int pitchtab[] = #define NOCTAVES (int)(__arraycount(pitchtab) / OCTAVE_NOTES) static void -playinit(void) +playinit(struct spkr_softc *sc) { - octave = DFLT_OCTAVE; - whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / DFLT_TEMPO; - fill = NORMAL; - value = DFLT_VALUE; - octtrack = false; - octprefix = true; /* act as though there was an initial O(n) */ + sc->sc_octave = DFLT_OCTAVE; + sc->sc_whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / DFLT_TEMPO; + sc->sc_fill = NORMAL; + sc->sc_value = DFLT_VALUE; + sc->sc_octtrack = false; + sc->sc_octprefix = true;/* act as though there was an initial O(n) */ } -static void -playtone(int pitch, int val, int sustain) /* play tone of proper duration for current rhythm signature */ +static void +playtone(struct spkr_softc *sc, int pitch, int val, int sustain) { - int sound, silence, snum = 1, sdenom = 1; + int sound, silence, snum = 1, sdenom = 1; - /* this weirdness avoids floating-point arithmetic */ - for (; sustain; sustain--) - { - snum *= NUM_MULT; - sdenom *= DENOM_MULT; - } + /* this weirdness avoids floating-point arithmetic */ + for (; sustain; sustain--) { + snum *= NUM_MULT; + sdenom *= DENOM_MULT; + } - if (pitch == -1) - spkr_rest(whole * snum / (val * sdenom)); - else - { - sound = (whole * snum) / (val * sdenom) - - (whole * (FILLTIME - fill)) / (val * FILLTIME); - silence = whole * (FILLTIME-fill) * snum / (FILLTIME * val * sdenom); + if (pitch == -1) { + (*sc->sc_rest)(sc->sc_hwdev, sc->sc_whole + * snum / (val * sdenom)); + return; + } + + int fac = sc->sc_whole * (FILLTIME - sc->sc_fill); + int fval = FILLTIME * val; + sound = (sc->sc_whole * snum) / (val * sdenom) - fac / fval; + silence = fac * snum / (fval * sdenom); #ifdef SPKRDEBUG - printf("playtone: pitch %d for %d ticks, rest for %d ticks\n", + aprint_debug_dev(sc->sc_hwdev, + "%s: pitch %d for %d ticks, rest for %d ticks\n", __func__, pitch, sound, silence); #endif /* SPKRDEBUG */ - spkr_tone(pitchtab[pitch], sound); - if (fill != LEGATO) - spkr_rest(silence); - } + (*sc->sc_tone)(sc->sc_hwdev, pitchtab[pitch], sound); + if (sc->sc_fill != LEGATO) + (*sc->sc_rest)(sc->sc_hwdev, silence); } -static void -playstring(char *cp, int slen) /* interpret and play an item from a notation string */ +static void +playstring(struct spkr_softc *sc, char *cp, int slen) { - int pitch, lastpitch = OCTAVE_NOTES * DFLT_OCTAVE; + int pitch, lastpitch = OCTAVE_NOTES * DFLT_OCTAVE; -#define GETNUM(cp, v) for(v=0; slen > 0 && isdigit(cp[1]); ) \ - {v = v * 10 + (*++cp - '0'); slen--;} - for (; slen--; cp++) - { - int sustain, timeval, tempo; - char c = toupper(*cp); +#define GETNUM(cp, v) \ + for (v = 0; slen > 0 && isdigit((unsigned char)cp[1]); ) { \ + v = v * 10 + (*++cp - '0'); \ + slen--; \ + } + + for (; slen--; cp++) { + int sustain, timeval, tempo; + char c = toupper((unsigned char)*cp); #ifdef SPKRDEBUG - printf("playstring: %c (%x)\n", c, c); + aprint_debug_dev(sc->sc_hwdev, "%s: %c (%x)\n", __func__, c, c); #endif /* SPKRDEBUG */ - switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': - - /* compute pitch */ - pitch = notetab[c - 'A'] + octave * OCTAVE_NOTES; - - /* this may be followed by an accidental sign */ - if (slen > 0 && (cp[1] == '#' || cp[1] == '+')) - { - ++pitch; - ++cp; - slen--; - } - else if (slen > 0 && cp[1] == '-') - { - --pitch; - ++cp; - slen--; - } - - /* - * If octave-tracking mode is on, and there has been no octave- - * setting prefix, find the version of the current letter note - * closest to the last regardless of octave. - */ - if (octtrack && !octprefix) - { - if (abs(pitch-lastpitch) > abs(pitch+OCTAVE_NOTES-lastpitch)) - { - if (octave < NOCTAVES - 1) { - ++octave; - pitch += OCTAVE_NOTES; - } - } + switch (c) { + case 'A': case 'B': case 'C': case 'D': + case 'E': case 'F': case 'G': + /* compute pitch */ + pitch = notetab[c - 'A'] + sc->sc_octave * OCTAVE_NOTES; + + /* this may be followed by an accidental sign */ + if (slen > 0 && (cp[1] == '#' || cp[1] == '+')) { + ++pitch; + ++cp; + slen--; + } else if (slen > 0 && cp[1] == '-') { + --pitch; + ++cp; + slen--; + } + + /* + * If octave-tracking mode is on, and there has been no + * octave- setting prefix, find the version of the + * current letter note * closest to the last + * regardless of octave. + */ + if (sc->sc_octtrack && !sc->sc_octprefix) { + int d = abs(pitch - lastpitch); + if (d > abs(pitch + OCTAVE_NOTES - lastpitch)) { + if (sc->sc_octave < NOCTAVES - 1) { + ++sc->sc_octave; + pitch += OCTAVE_NOTES; + } + } + + if (d > abs(pitch - OCTAVE_NOTES - lastpitch)) { + if (sc->sc_octave > 0) { + --sc->sc_octave; + pitch -= OCTAVE_NOTES; + } + } + } + sc->sc_octprefix = false; + lastpitch = pitch; + + /* + * ...which may in turn be followed by an override + * time value + */ + GETNUM(cp, timeval); + if (timeval <= 0 || timeval > MIN_VALUE) + timeval = sc->sc_value; + + /* ...and/or sustain dots */ + for (sustain = 0; slen > 0 && cp[1] == '.'; cp++) { + slen--; + sustain++; + } + + /* time to emit the actual tone */ + playtone(sc, pitch, timeval, sustain); + break; + + case 'O': + if (slen > 0 && (cp[1] == 'N' || cp[1] == 'n')) { + sc->sc_octprefix = sc->sc_octtrack = false; + ++cp; + slen--; + } else if (slen > 0 && (cp[1] == 'L' || cp[1] == 'l')) { + sc->sc_octtrack = true; + ++cp; + slen--; + } else { + GETNUM(cp, sc->sc_octave); + if (sc->sc_octave >= NOCTAVES) + sc->sc_octave = DFLT_OCTAVE; + sc->sc_octprefix = true; + } + break; + + case '>': + if (sc->sc_octave < NOCTAVES - 1) + sc->sc_octave++; + sc->sc_octprefix = true; + break; + + case '<': + if (sc->sc_octave > 0) + sc->sc_octave--; + sc->sc_octprefix = true; + break; + + case 'N': + GETNUM(cp, pitch); + for (sustain = 0; slen > 0 && cp[1] == '.'; cp++) { + slen--; + sustain++; + } + playtone(sc, pitch - 1, sc->sc_value, sustain); + break; - if (abs(pitch-lastpitch) > abs((pitch-OCTAVE_NOTES)-lastpitch)) - { - if (octave > 0) { - --octave; - pitch -= OCTAVE_NOTES; - } + case 'L': + GETNUM(cp, sc->sc_value); + if (sc->sc_value <= 0 || sc->sc_value > MIN_VALUE) + sc->sc_value = DFLT_VALUE; + break; + + case 'P': + case '~': + /* this may be followed by an override time value */ + GETNUM(cp, timeval); + if (timeval <= 0 || timeval > MIN_VALUE) + timeval = sc->sc_value; + for (sustain = 0; slen > 0 && cp[1] == '.'; cp++) { + slen--; + sustain++; + } + playtone(sc, -1, timeval, sustain); + break; + + case 'T': + GETNUM(cp, tempo); + if (tempo < MIN_TEMPO || tempo > MAX_TEMPO) + tempo = DFLT_TEMPO; + sc->sc_whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / tempo; + break; + + case 'M': + if (slen > 0 && (cp[1] == 'N' || cp[1] == 'n')) { + sc->sc_fill = NORMAL; + ++cp; + slen--; + } else if (slen > 0 && (cp[1] == 'L' || cp[1] == 'l')) { + sc->sc_fill = LEGATO; + ++cp; + slen--; + } else if (slen > 0 && (cp[1] == 'S' || cp[1] == 's')) { + sc->sc_fill = STACCATO; + ++cp; + slen--; + } + break; } - } - octprefix = false; - lastpitch = pitch; - - /* ...which may in turn be followed by an override time value */ - GETNUM(cp, timeval); - if (timeval <= 0 || timeval > MIN_VALUE) - timeval = value; - - /* ...and/or sustain dots */ - for (sustain = 0; slen > 0 && cp[1] == '.'; cp++) - { - slen--; - sustain++; - } - - /* time to emit the actual tone */ - playtone(pitch, timeval, sustain); - break; - - case 'O': - if (slen > 0 && (cp[1] == 'N' || cp[1] == 'n')) - { - octprefix = octtrack = false; - ++cp; - slen--; - } - else if (slen > 0 && (cp[1] == 'L' || cp[1] == 'l')) - { - octtrack = true; - ++cp; - slen--; - } - else - { - GETNUM(cp, octave); - if (octave >= NOCTAVES) - octave = DFLT_OCTAVE; - octprefix = true; - } - break; - - case '>': - if (octave < NOCTAVES - 1) - octave++; - octprefix = true; - break; - - case '<': - if (octave > 0) - octave--; - octprefix = true; - break; - - case 'N': - GETNUM(cp, pitch); - for (sustain = 0; slen > 0 && cp[1] == '.'; cp++) - { - slen--; - sustain++; - } - playtone(pitch - 1, value, sustain); - break; - - case 'L': - GETNUM(cp, value); - if (value <= 0 || value > MIN_VALUE) - value = DFLT_VALUE; - break; - - case 'P': - case '~': - /* this may be followed by an override time value */ - GETNUM(cp, timeval); - if (timeval <= 0 || timeval > MIN_VALUE) - timeval = value; - for (sustain = 0; slen > 0 && cp[1] == '.'; cp++) - { - slen--; - sustain++; - } - playtone(-1, timeval, sustain); - break; - - case 'T': - GETNUM(cp, tempo); - if (tempo < MIN_TEMPO || tempo > MAX_TEMPO) - tempo = DFLT_TEMPO; - whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / tempo; - break; - - case 'M': - if (slen > 0 && (cp[1] == 'N' || cp[1] == 'n')) - { - fill = NORMAL; - ++cp; - slen--; - } - else if (slen > 0 && (cp[1] == 'L' || cp[1] == 'l')) - { - fill = LEGATO; - ++cp; - slen--; - } - else if (slen > 0 && (cp[1] == 'S' || cp[1] == 's')) - { - fill = STACCATO; - ++cp; - slen--; - } - break; } - } } /******************* UNIX DRIVER HOOKS BEGIN HERE ************************** @@ -366,118 +368,163 @@ playstring(char *cp, int slen) * This section implements driver hooks to run playstring() and the spkr_tone() * and spkr_rest() functions defined above. */ +static int spkrprobe(device_t, cfdata_t, void *); +static void spkrattach(device_t, device_t, void *); -static int spkr_active; /* exclusion flag */ -int spkr_attached; -static void *spkr_inbuf; +CFATTACH_DECL3_NEW(spkr, sizeof(struct spkr_softc), + spkrprobe, spkrattach, NULL, NULL, NULL, NULL, + DVF_DETACH_SHUTDOWN); -int -spkr_probe(device_t parent, cfdata_t match, void *aux) +extern struct cfdriver spkr_cd; +#define spkrenter(d) device_lookup_private(&spkr_cd, d) + +static int +spkrprobe(device_t parent, cfdata_t match, void *aux) { - return (!spkr_attached); + struct spkr_attach_args *sa = aux; + return sa->sa_sig == SPKR_SIG; +} + +static void +spkrattach(device_t parent, device_t self, void *aux) +{ + struct spkr_softc *sc = device_private(self); + struct spkr_attach_args *sa = aux; + + sc->sc_dev = self; + sc->sc_hwdev = sa->sa_dev; + sc->sc_rest = sa->sa_rest; + sc->sc_tone = sa->sa_tone; + sc->sc_inbuf = NULL; + aprint_normal("\n"); } int spkropen(dev_t dev, int flags, int mode, struct lwp *l) { #ifdef SPKRDEBUG - printf("spkropen: entering with dev = %"PRIx64"\n", dev); + aprint_debug("%s: entering with dev = %"PRIx64"\n", __func__, dev); #en