1*c7fb772bSthorpej /* $NetBSD: ms_kbc.c,v 1.14 2021/08/07 16:19:00 thorpej Exp $ */
208f4daf2Stsutsui
308f4daf2Stsutsui /*-
408f4daf2Stsutsui * Copyright (c) 2001 Izumi Tsutsui. All rights reserved.
5b87210faStsutsui *
6b87210faStsutsui * Redistribution and use in source and binary forms, with or without
7b87210faStsutsui * modification, are permitted provided that the following conditions
8b87210faStsutsui * are met:
9b87210faStsutsui * 1. Redistributions of source code must retain the above copyright
10b87210faStsutsui * notice, this list of conditions and the following disclaimer.
11b87210faStsutsui * 2. Redistributions in binary form must reproduce the above copyright
12b87210faStsutsui * notice, this list of conditions and the following disclaimer in the
13b87210faStsutsui * documentation and/or other materials provided with the distribution.
14b87210faStsutsui *
15b87210faStsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16b87210faStsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17b87210faStsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18b87210faStsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19b87210faStsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20b87210faStsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21b87210faStsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22b87210faStsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23b87210faStsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24b87210faStsutsui * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25b87210faStsutsui */
26b87210faStsutsui
27b87210faStsutsui /*-
2808f4daf2Stsutsui * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
2908f4daf2Stsutsui *
3008f4daf2Stsutsui * Redistribution and use in source and binary forms, with or without
3108f4daf2Stsutsui * modification, are permitted provided that the following conditions
3208f4daf2Stsutsui * are met:
3308f4daf2Stsutsui * 1. Redistributions of source code must retain the above copyright
3408f4daf2Stsutsui * notice, this list of conditions and the following disclaimer.
3508f4daf2Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
3608f4daf2Stsutsui * notice, this list of conditions and the following disclaimer in the
3708f4daf2Stsutsui * documentation and/or other materials provided with the distribution.
3808f4daf2Stsutsui * 3. The name of the author may not be used to endorse or promote products
3908f4daf2Stsutsui * derived from this software without specific prior written permission.
4008f4daf2Stsutsui *
4108f4daf2Stsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
4208f4daf2Stsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
4308f4daf2Stsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
4408f4daf2Stsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
4508f4daf2Stsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4608f4daf2Stsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4708f4daf2Stsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4808f4daf2Stsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4908f4daf2Stsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5008f4daf2Stsutsui * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5108f4daf2Stsutsui */
5208f4daf2Stsutsui
53ed517291Slukem #include <sys/cdefs.h>
54*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: ms_kbc.c,v 1.14 2021/08/07 16:19:00 thorpej Exp $");
55ed517291Slukem
5608f4daf2Stsutsui #include <sys/param.h>
5708f4daf2Stsutsui #include <sys/device.h>
5808f4daf2Stsutsui #include <sys/systm.h>
5908f4daf2Stsutsui
6008f4daf2Stsutsui #include <dev/wscons/wsconsio.h>
6108f4daf2Stsutsui #include <dev/wscons/wsmousevar.h>
6208f4daf2Stsutsui
6308f4daf2Stsutsui #include <machine/cpu.h>
6408f4daf2Stsutsui #include <machine/bus.h>
6508f4daf2Stsutsui
6608f4daf2Stsutsui #include <news68k/dev/kbcreg.h>
6708f4daf2Stsutsui #include <news68k/dev/kbcvar.h>
6808f4daf2Stsutsui #include <news68k/dev/msvar.h>
6908f4daf2Stsutsui
7008f4daf2Stsutsui #include <news68k/news68k/isr.h>
7108f4daf2Stsutsui
72820a544dStsutsui static int ms_kbc_match(device_t, cfdata_t, void *);
73820a544dStsutsui static void ms_kbc_attach(device_t, device_t, void *);
7452b46dcfStsutsui static void ms_kbc_init(struct ms_softc *);
7508f4daf2Stsutsui int ms_kbc_intr(void *);
7608f4daf2Stsutsui
7752b46dcfStsutsui static int ms_kbc_enable(void *);
7852b46dcfStsutsui static void ms_kbc_disable(void *);
7953524e44Schristos static int ms_kbc_ioctl(void *, u_long, void *, int, struct lwp *);
8008f4daf2Stsutsui
81820a544dStsutsui CFATTACH_DECL_NEW(ms_kbc, sizeof(struct ms_softc),
82021b694dSthorpej ms_kbc_match, ms_kbc_attach, NULL, NULL);
8308f4daf2Stsutsui
8408f4daf2Stsutsui struct wsmouse_accessops ms_kbc_accessops = {
8508f4daf2Stsutsui ms_kbc_enable,
8608f4daf2Stsutsui ms_kbc_ioctl,
8708f4daf2Stsutsui ms_kbc_disable
8808f4daf2Stsutsui };
8908f4daf2Stsutsui
9052b46dcfStsutsui static int
ms_kbc_match(device_t parent,cfdata_t cf,void * aux)91820a544dStsutsui ms_kbc_match(device_t parent, cfdata_t cf, void *aux)
9208f4daf2Stsutsui {
9308f4daf2Stsutsui struct kbc_attach_args *ka = aux;
9408f4daf2Stsutsui
9508f4daf2Stsutsui if (strcmp(ka->ka_name, "ms"))
9608f4daf2Stsutsui return 0;
9708f4daf2Stsutsui
9808f4daf2Stsutsui return 1;
9908f4daf2Stsutsui }
10008f4daf2Stsutsui
10152b46dcfStsutsui static void
ms_kbc_attach(device_t parent,device_t self,void * aux)102820a544dStsutsui ms_kbc_attach(device_t parent, device_t self, void *aux)
10308f4daf2Stsutsui {
104820a544dStsutsui struct ms_softc *sc = device_private(self);
10508f4daf2Stsutsui struct kbc_attach_args *ka = aux;
10608f4daf2Stsutsui struct wsmousedev_attach_args wsa;
10708f4daf2Stsutsui int ipl;
10808f4daf2Stsutsui
109d062717cStsutsui sc->sc_dev = self;
110820a544dStsutsui aprint_normal("\n");
11108f4daf2Stsutsui
11208f4daf2Stsutsui sc->sc_bt = ka->ka_bt;
11308f4daf2Stsutsui sc->sc_bh = ka->ka_bh;
11408f4daf2Stsutsui sc->sc_offset = KBC_MSREG_DATA;
11508f4daf2Stsutsui ipl = ka->ka_ipl;
11608f4daf2Stsutsui
11708f4daf2Stsutsui ms_kbc_init(sc);
11808f4daf2Stsutsui
1197d0e6302Stsutsui isrlink_autovec(ms_kbc_intr, (void *)sc, ipl, IPL_TTY);
12008f4daf2Stsutsui
12108f4daf2Stsutsui wsa.accessops = &ms_kbc_accessops;
12208f4daf2Stsutsui wsa.accesscookie = sc;
1232685996bSthorpej sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint,
124*c7fb772bSthorpej CFARGS_NONE);
12508f4daf2Stsutsui }
12608f4daf2Stsutsui
12752b46dcfStsutsui static void
ms_kbc_init(struct ms_softc * sc)12852b46dcfStsutsui ms_kbc_init(struct ms_softc *sc)
12908f4daf2Stsutsui {
13008f4daf2Stsutsui bus_space_tag_t bt = sc->sc_bt;
13108f4daf2Stsutsui bus_space_handle_t bh = sc->sc_bh;
13208f4daf2Stsutsui
13308f4daf2Stsutsui bus_space_write_1(bt, bh, KBC_MSREG_RESET, 0);
13408f4daf2Stsutsui bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
13508f4daf2Stsutsui }
13608f4daf2Stsutsui
13708f4daf2Stsutsui int
ms_kbc_intr(void * v)13852b46dcfStsutsui ms_kbc_intr(void *v)
13908f4daf2Stsutsui {
14008f4daf2Stsutsui struct ms_softc *sc = v;
14108f4daf2Stsutsui bus_space_tag_t bt = sc->sc_bt;
14208f4daf2Stsutsui bus_space_handle_t bh = sc->sc_bh;
14308f4daf2Stsutsui int handled = 0;
14408f4daf2Stsutsui
14508f4daf2Stsutsui while (bus_space_read_1(bt, bh, KBC_MSREG_STAT) & KBCSTAT_MSRDY) {
14608f4daf2Stsutsui ms_intr(sc);
14708f4daf2Stsutsui handled = 1;
14808f4daf2Stsutsui }
14908f4daf2Stsutsui if (handled)
15008f4daf2Stsutsui bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
15108f4daf2Stsutsui
15208f4daf2Stsutsui return handled;
15308f4daf2Stsutsui }
15408f4daf2Stsutsui
15552b46dcfStsutsui static int
ms_kbc_enable(void * v)15652b46dcfStsutsui ms_kbc_enable(void *v)
15708f4daf2Stsutsui {
15808f4daf2Stsutsui struct ms_softc *sc = v;
15908f4daf2Stsutsui bus_space_tag_t bt = sc->sc_bt;
16008f4daf2Stsutsui bus_space_handle_t bh = sc->sc_bh;
16108f4daf2Stsutsui
16208f4daf2Stsutsui bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
16308f4daf2Stsutsui
16408f4daf2Stsutsui return 0;
16508f4daf2Stsutsui }
16608f4daf2Stsutsui
16752b46dcfStsutsui static void
ms_kbc_disable(void * v)16852b46dcfStsutsui ms_kbc_disable(void *v)
16908f4daf2Stsutsui {
17008f4daf2Stsutsui struct ms_softc *sc = v;
17108f4daf2Stsutsui bus_space_tag_t bt = sc->sc_bt;
17208f4daf2Stsutsui bus_space_handle_t bh = sc->sc_bh;
17308f4daf2Stsutsui
17408f4daf2Stsutsui bus_space_write_1(bt, bh, KBC_MSREG_INTE, 0);
17508f4daf2Stsutsui }
17608f4daf2Stsutsui
17752b46dcfStsutsui static int
ms_kbc_ioctl(void * v,u_long cmd,void * data,int flag,struct lwp * l)17853524e44Schristos ms_kbc_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
17908f4daf2Stsutsui {
18052b46dcfStsutsui
18131144d99Satatat return EPASSTHROUGH;
18208f4daf2Stsutsui }
183