Sat Jun 3 17:03:36 2017 UTC ()
Add driver for ARM PrimeCell PL050 (KMI) PS2 keyboard/mouse interface
(jmcneill)
diff -r1.1172 -r1.1173 src/sys/conf/files
diff -r0 -r1.1 src/sys/dev/ic/pl050.c
diff -r0 -r1.1 src/sys/dev/ic/pl050var.h
--- src/sys/conf/files 2017/05/27 21:02:56 1.1172
+++ src/sys/conf/files 2017/06/03 17:03:36 1.1173
| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: files,v 1.1172 2017/05/27 21:02:56 bouyer Exp $ | | 1 | # $NetBSD: files,v 1.1173 2017/06/03 17:03:36 jmcneill Exp $ |
2 | # @(#)files.newconf 7.5 (Berkeley) 5/10/93 | | 2 | # @(#)files.newconf 7.5 (Berkeley) 5/10/93 |
3 | | | 3 | |
4 | version 20150846 | | 4 | version 20150846 |
5 | | | 5 | |
6 | # | | 6 | # |
7 | # device classes | | 7 | # device classes |
8 | # | | 8 | # |
9 | devclass disk | | 9 | devclass disk |
10 | devclass tape | | 10 | devclass tape |
11 | devclass ifnet | | 11 | devclass ifnet |
12 | devclass tty | | 12 | devclass tty |
13 | devclass audiodev | | 13 | devclass audiodev |
14 | devclass displaydev | | 14 | devclass displaydev |
| @@ -1305,26 +1305,30 @@ file dev/sdmmc/sdhc.c sdhc needs-flag | | | @@ -1305,26 +1305,30 @@ file dev/sdmmc/sdhc.c sdhc needs-flag |
1305 | device wb: sdmmcbus | | 1305 | device wb: sdmmcbus |
1306 | file dev/ic/w83l518d.c wb | | 1306 | file dev/ic/w83l518d.c wb |
1307 | file dev/ic/w83l518d_sdmmc.c wb | | 1307 | file dev/ic/w83l518d_sdmmc.c wb |
1308 | | | 1308 | |
1309 | # Realtek RTS5209/RTS5229 Card Reader | | 1309 | # Realtek RTS5209/RTS5229 Card Reader |
1310 | device rtsx: sdmmcbus | | 1310 | device rtsx: sdmmcbus |
1311 | file dev/ic/rtsx.c rtsx | | 1311 | file dev/ic/rtsx.c rtsx |
1312 | | | 1312 | |
1313 | # DesignWare SD/MMC host controller | | 1313 | # DesignWare SD/MMC host controller |
1314 | defflag opt_dwc_mmc.h DWC_MMC_DEBUG | | 1314 | defflag opt_dwc_mmc.h DWC_MMC_DEBUG |
1315 | device dwcmmc: sdmmcbus | | 1315 | device dwcmmc: sdmmcbus |
1316 | file dev/ic/dwc_mmc.c dwcmmc | | 1316 | file dev/ic/dwc_mmc.c dwcmmc |
1317 | | | 1317 | |
| | | 1318 | # ARM PrimeCell PL050 (KMI) PS2 keyboard/mouse interface |
| | | 1319 | device plkmi: pckbport |
| | | 1320 | file dev/ic/pl050.c plkmi |
| | | 1321 | |
1318 | # ARM PrimeCell PL181 (MMCI) host controller | | 1322 | # ARM PrimeCell PL181 (MMCI) host controller |
1319 | device plmmc: sdmmcbus | | 1323 | device plmmc: sdmmcbus |
1320 | file dev/ic/pl181.c plmmc | | 1324 | file dev/ic/pl181.c plmmc |
1321 | | | 1325 | |
1322 | # Myson MTD803 3-in-1 Fast Ethernet Controller | | 1326 | # Myson MTD803 3-in-1 Fast Ethernet Controller |
1323 | device mtd: arp, ether, ifnet, mii | | 1327 | device mtd: arp, ether, ifnet, mii |
1324 | file dev/ic/mtd803.c mtd | | 1328 | file dev/ic/mtd803.c mtd |
1325 | | | 1329 | |
1326 | # radio devices, attaches to radio hardware driver | | 1330 | # radio devices, attaches to radio hardware driver |
1327 | device radio | | 1331 | device radio |
1328 | attach radio at radiodev | | 1332 | attach radio at radiodev |
1329 | | | 1333 | |
1330 | # IEEE 1394 controllers | | 1334 | # IEEE 1394 controllers |
/* $NetBSD: pl050.c,v 1.1 2017/06/03 17:03:36 jmcneill Exp $ */
/*-
* Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca>
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pl050.c,v 1.1 2017/06/03 17:03:36 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kmem.h>
#include <sys/bus.h>
#include <dev/pckbport/pckbportvar.h>
#include <dev/ic/pl050var.h>
#define KMICR 0x00
#define KMIRXINTREN __BIT(4)
#define KMIEN __BIT(2)
#define KMISTAT 0x04
#define TXEMPTY __BIT(6)
#define RXFULL __BIT(4)
#define KMIDATA 0x08
#define KMICLKDIV 0x0c
#define KMIIR 0x10
#define KMIRXINTR __BIT(0)
#define PLKMI_READ(sc, reg) \
bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
#define PLKMI_WRITE(sc, reg, val) \
bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
static int
plkmi_wait(struct plkmi_softc *sc, uint32_t mask, bool set)
{
int timeout = 1000;
const uint32_t val = (set ? mask : 0);
while (timeout-- > 0) {
const uint32_t stat = PLKMI_READ(sc, KMISTAT);
if ((stat & mask) == val)
return 0;
delay(10);
}
return ETIMEDOUT;
}
static int
plkmi_xt_translation(void *priv, pckbport_slot_t port, int on)
{
if (on)
return 0;
return 1;
}
static int
plkmi_send_devcmd(void *priv, pckbport_slot_t slot, u_char byte)
{
struct plkmi_softc * const sc = priv;
if (plkmi_wait(sc, TXEMPTY, true))
return 0;
PLKMI_WRITE(sc, KMIDATA, byte & 0xff);
return 1;
}
static int
plkmi_poll_data1(void *priv, pckbport_slot_t slot)
{
struct plkmi_softc * const sc = priv;
if (plkmi_wait(sc, RXFULL, true))
return -1;
return PLKMI_READ(sc, KMIDATA) & 0xff;
}
static void
plkmi_slot_enable(void *priv, pckbport_slot_t slot, int on)
{
struct plkmi_softc * const sc = priv;
uint32_t cr;
cr = PLKMI_READ(sc, KMICR);
if (on)
cr |= KMIEN;
else
cr &= ~KMIEN;
PLKMI_WRITE(sc, KMICR, cr);
}
static void
plkmi_set_poll(void *priv, pckbport_slot_t slot, int on)
{
struct plkmi_softc * const sc = priv;
uint32_t cr;
cr = PLKMI_READ(sc, KMICR);
if (on)
cr &= ~KMIRXINTREN;
else
cr |= KMIRXINTREN;
PLKMI_WRITE(sc, KMICR, cr);
}
static void
plkmi_intr_establish(void *priv, pckbport_slot_t slot)
{
/* XXX */
plkmi_set_poll(priv, slot, 0);
}
static struct pckbport_accessops plkmi_ops = {
.t_xt_translation = plkmi_xt_translation,
.t_send_devcmd = plkmi_send_devcmd,
.t_poll_data1 = plkmi_poll_data1,
.t_slot_enable = plkmi_slot_enable,
.t_set_poll = plkmi_set_poll,
.t_intr_establish = plkmi_intr_establish,
};
void
plkmi_attach(struct plkmi_softc *sc)
{
aprint_naive("\n");
aprint_normal(": PS2 controller\n");
sc->sc_pt = pckbport_attach(sc, &plkmi_ops);
sc->sc_slot = -1;
PLKMI_WRITE(sc, KMICR, KMIEN);
for (int slot = 0; slot < PCKBPORT_NSLOTS; slot++)
if (pckbport_attach_slot(sc->sc_dev, sc->sc_pt, slot)) {
sc->sc_slot = slot;
break;
}
}
int
plkmi_intr(void *priv)
{
struct plkmi_softc * const sc = priv;
int handled = 0;
if (sc->sc_slot == -1)
return 0;
const uint32_t stat = PLKMI_READ(sc, KMISTAT);
if (stat & RXFULL) {
const uint32_t val = PLKMI_READ(sc, KMIDATA);
pckbportintr(sc->sc_pt, sc->sc_slot, val & 0xff);
handled = 1;
}
return handled;
}
/* $NetBSD: pl050var.h,v 1.1 2017/06/03 17:03:36 jmcneill Exp $ */
/*-
* Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca>
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _PL050VAR_H
#define _PL050VAR_H
#include <dev/pckbport/pckbportvar.h>
struct plkmi_softc {
device_t sc_dev;
bus_space_tag_t sc_bst;
bus_space_handle_t sc_bsh;
pckbport_tag_t sc_pt;
int sc_slot;
};
void plkmi_attach(struct plkmi_softc *);
int plkmi_intr(void *);
#endif /* !_PL050VAR_H */