/*
* Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
if (mode) {
mfp_bit_set_iera(MFP_INTR_RCV_FULL);
/*
* Perform null read in case that an input byte is in the
* receiver buffer, which prevents further interrupts.
* We could save the input, but probably not so valuable.
*/
(void) mfp_get_udr();
}
kbdled = 0; /* all keyboard LED turn off. */
kbd_setLED();
if (!(intio_get_sysport_keyctrl() & 8))
aprint_normal(" (no connected keyboard)");
}
static int
kbdopen(dev_t dev, int flags, int mode, struct lwp *l)
{
struct kbd_softc *k;
k = device_lookup_private(&kbd_cd, minor(dev));
if (k == NULL)
return (ENXIO);
if (k->sc_events.ev_io)
return (EBUSY);
k->sc_events.ev_io = l->l_proc;
ev_init(&k->sc_events, device_xname(k->sc_dev), &k->sc_lock);
return (0);
}
static int
kbdclose(dev_t dev, int flags, int mode, struct lwp *l)
{
struct kbd_softc *k = device_lookup_private(&kbd_cd, minor(dev));
/* Turn off event mode, dump the queue */
k->sc_event_mode = 0;
ev_fini(&k->sc_events);
k->sc_events.ev_io = NULL;
return (0);
}
static int
kbdread(dev_t dev, struct uio *uio, int flags)
{
struct kbd_softc *k = device_lookup_private(&kbd_cd, minor(dev));
k = device_lookup_private(&kbd_cd, minor(dev));
return (ev_kqfilter(&k->sc_events, kn));
}
#define KBDBUFMASK 63
#define KBDBUFSIZ 64
static u_char kbdbuf[KBDBUFSIZ];
static int kbdputoff = 0;
static int kbdgetoff = 0;
static int
kbdintr(void *arg)
{
uint8_t c, st;
struct kbd_softc *sc = arg;
struct firm_event *fe;
int put;
/* clear receiver error if any */
st = mfp_get_rsr();
c = mfp_get_udr();
rnd_add_uint32(&sc->sc_rndsource, (st << 8) | c);
if ((st & MFP_RSR_BF) == 0)
return 0; /* intr caused by an err -- no char received */
/* if not in event mode, deliver straight to ite to process key stroke */
if (!sc->sc_event_mode) {
kbdbuf[kbdputoff++ & KBDBUFMASK] = c;
softint_schedule(sc->sc_softintr_cookie);
return 0;
}
/* Keyboard is generating events. Turn this keystroke into an
event and put it in the queue. If the queue is full, the
keystroke is lost (sorry!). */